home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / gas / config / tc-i960.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-04  |  86.1 KB  |  3,253 lines

  1. /* tc-i960.c - All the i80960-specific stuff
  2.    Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20. /* See comment on md_parse_option for 80960-specific invocation options. */
  21.  
  22. /* There are 4 different lengths of (potentially) symbol-based displacements
  23.    in the 80960 instruction set, each of which could require address fix-ups
  24.    and (in the case of external symbols) emission of relocation directives:
  25.  
  26.    32-bit (MEMB)
  27.         This is a standard length for the base assembler and requires no
  28.         special action.
  29.  
  30.    13-bit (COBR)
  31.         This is a non-standard length, but the base assembler has a
  32.         hook for bit field address fixups: the fixS structure can
  33.         point to a descriptor of the field, in which case our
  34.         md_number_to_field() routine gets called to process it.
  35.  
  36.         I made the hook a little cleaner by having fix_new() (in the base
  37.         assembler) return a pointer to the fixS in question.  And I made it a
  38.         little simpler by storing the field size (in this case 13) instead of
  39.         of a pointer to another structure:  80960 displacements are ALWAYS
  40.         stored in the low-order bits of a 4-byte word.
  41.  
  42.         Since the target of a COBR cannot be external, no relocation
  43.         directives for this size displacement have to be generated.
  44.         But the base assembler had to be modified to issue error
  45.         messages if the symbol did turn out to be external.
  46.  
  47.    24-bit (CTRL)
  48.         Fixups are handled as for the 13-bit case (except that 24 is stored
  49.         in the fixS).
  50.  
  51.         The relocation directive generated is the same as that for the 32-bit
  52.         displacement, except that it's PC-relative (the 32-bit displacement
  53.         never is).   The i80960 version of the linker needs a mod to
  54.         distinguish and handle the 24-bit case.
  55.  
  56.    12-bit (MEMA)
  57.         MEMA formats are always promoted to MEMB (32-bit) if the displacement
  58.         is based on a symbol, because it could be relocated at link time.
  59.         The only time we use the 12-bit format is if an absolute value of
  60.         less than 4096 is specified, in which case we need neither a fixup nor
  61.         a relocation directive.  */
  62.  
  63. #include <stdio.h>
  64. #include <ctype.h>
  65.  
  66. #include "as.h"
  67.  
  68. #include "obstack.h"
  69.  
  70. #include "opcode/i960.h"
  71.  
  72. #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
  73.  
  74. #define TC_S_IS_SYSPROC(s)    ((1<=S_GET_OTHER(s)) && (S_GET_OTHER(s)<=32))
  75. #define TC_S_IS_BALNAME(s)    (S_GET_OTHER(s) == N_BALNAME)
  76. #define TC_S_IS_CALLNAME(s)    (S_GET_OTHER(s) == N_CALLNAME)
  77. #define TC_S_IS_BADPROC(s)    ((S_GET_OTHER(s) != 0) && !TC_S_IS_CALLNAME(s) && !TC_S_IS_BALNAME(s) && !TC_S_IS_SYSPROC(s))
  78.  
  79. #define TC_S_SET_SYSPROC(s, p)    (S_SET_OTHER((s), (p)+1))
  80. #define TC_S_GET_SYSPROC(s)    (S_GET_OTHER(s)-1)
  81.  
  82. #define TC_S_FORCE_TO_BALNAME(s)    (S_SET_OTHER((s), N_BALNAME))
  83. #define TC_S_FORCE_TO_CALLNAME(s)    (S_SET_OTHER((s), N_CALLNAME))
  84. #define TC_S_FORCE_TO_SYSPROC(s)    {;}
  85.  
  86. #else /* ! OBJ_A/BOUT */
  87. #ifdef OBJ_COFF
  88.  
  89. #define TC_S_IS_SYSPROC(s)    (S_GET_STORAGE_CLASS(s) == C_SCALL)
  90. #define TC_S_IS_BALNAME(s)    (SF_GET_BALNAME(s))
  91. #define TC_S_IS_CALLNAME(s)    (SF_GET_CALLNAME(s))
  92. #define TC_S_IS_BADPROC(s)    (TC_S_IS_SYSPROC(s) && TC_S_GET_SYSPROC(s) < 0 && 31 < TC_S_GET_SYSPROC(s))
  93.  
  94. #define TC_S_SET_SYSPROC(s, p)    ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx = (p))
  95. #define TC_S_GET_SYSPROC(s)    ((s)->sy_symbol.ost_auxent[1].x_sc.x_stindx)
  96.  
  97. #define TC_S_FORCE_TO_BALNAME(s)    (SF_SET_BALNAME(s))
  98. #define TC_S_FORCE_TO_CALLNAME(s)    (SF_SET_CALLNAME(s))
  99. #define TC_S_FORCE_TO_SYSPROC(s)    (S_SET_STORAGE_CLASS((s), C_SCALL))
  100.  
  101. #else /* ! OBJ_COFF */
  102. you lose;
  103. #endif /* ! OBJ_COFF */
  104. #endif /* ! OBJ_A/BOUT */
  105.  
  106. extern char *input_line_pointer;
  107.  
  108. #if !defined (BFD_ASSEMBLER) && !defined (BFD)
  109. #ifdef OBJ_COFF
  110. const int md_reloc_size = sizeof (struct reloc);
  111. #else /* OBJ_COFF */
  112. const int md_reloc_size = sizeof (struct relocation_info);
  113. #endif /* OBJ_COFF */
  114. #endif
  115.  
  116. /* Local i80960 routines.  */
  117.  
  118. static void brcnt_emit ();    /* Emit branch-prediction instrumentation code */
  119. static char *brlab_next ();    /* Return next branch local label */
  120. void brtab_emit ();        /* Emit br-predict instrumentation table */
  121. static void cobr_fmt ();    /* Generate COBR instruction */
  122. static void ctrl_fmt ();    /* Generate CTRL instruction */
  123. static char *emit ();        /* Emit (internally) binary */
  124. static int get_args ();        /* Break arguments out of comma-separated list */
  125. static void get_cdisp ();    /* Handle COBR or CTRL displacement */
  126. static char *get_ispec ();    /* Find index specification string */
  127. static int get_regnum ();    /* Translate text to register number */
  128. static int i_scan ();        /* Lexical scan of instruction source */
  129. static void mem_fmt ();        /* Generate MEMA or MEMB instruction */
  130. static void mema_to_memb ();    /* Convert MEMA instruction to MEMB format */
  131. static void parse_expr ();    /* Parse an expression */
  132. static int parse_ldconst ();    /* Parse and replace a 'ldconst' pseudo-op */
  133. static void parse_memop ();    /* Parse a memory operand */
  134. static void parse_po ();    /* Parse machine-dependent pseudo-op */
  135. static void parse_regop ();    /* Parse a register operand */
  136. static void reg_fmt ();        /* Generate a REG format instruction */
  137. void reloc_callj ();        /* Relocate a 'callj' instruction */
  138. static void relax_cobr ();    /* "De-optimize" cobr into compare/branch */
  139. static void s_leafproc ();    /* Process '.leafproc' pseudo-op */
  140. static void s_sysproc ();    /* Process '.sysproc' pseudo-op */
  141. static int shift_ok ();        /* Will a 'shlo' substiture for a 'ldconst'? */
  142. static void syntax ();        /* Give syntax error */
  143. static int targ_has_sfr ();    /* Target chip supports spec-func register? */
  144. static int targ_has_iclass ();    /* Target chip supports instruction set? */
  145.  
  146. /* See md_parse_option() for meanings of these options */
  147. static char norelax;        /* True if -norelax switch seen */
  148. static char instrument_branches;    /* True if -b switch seen */
  149.  
  150. /* Characters that always start a comment.
  151.    If the pre-processor is disabled, these aren't very useful.
  152.  */
  153. const char comment_chars[] = "#";
  154.  
  155. /* Characters that only start a comment at the beginning of
  156.    a line.  If the line seems to have the form '# 123 filename'
  157.    .line and .file directives will appear in the pre-processed output.
  158.  
  159.    Note that input_file.c hand checks for '#' at the beginning of the
  160.    first line of the input file.  This is because the compiler outputs
  161.    #NO_APP at the beginning of its output.
  162.  */
  163.  
  164. /* Also note that comments started like this one will always work. */
  165.  
  166. const char line_comment_chars[1];
  167.  
  168. const char line_separator_chars[1];
  169.  
  170. /* Chars that can be used to separate mant from exp in floating point nums */
  171. const char EXP_CHARS[] = "eE";
  172.  
  173. /* Chars that mean this number is a floating point constant,
  174.    as in 0f12.456 or 0d1.2345e12
  175.  */
  176. const char FLT_CHARS[] = "fFdDtT";
  177.  
  178.  
  179. /* Table used by base assembler to relax addresses based on varying length
  180.    instructions.  The fields are:
  181.      1) most positive reach of this state,
  182.      2) most negative reach of this state,
  183.      3) how many bytes this mode will add to the size of the current frag
  184.      4) which index into the table to try if we can't fit into this one.
  185.  
  186.    For i80960, the only application is the (de-)optimization of cobr
  187.    instructions into separate compare and branch instructions when a 13-bit
  188.    displacement won't hack it.
  189.  */
  190. const relax_typeS md_relax_table[] =
  191. {
  192.   {0, 0, 0, 0},            /* State 0 => no more relaxation possible */
  193.   {4088, -4096, 0, 2},        /* State 1: conditional branch (cobr) */
  194.   {0x800000 - 8, -0x800000, 4, 0},    /* State 2: compare (reg) & branch (ctrl) */
  195. };
  196.  
  197. static void s_endian PARAMS ((int));
  198.  
  199. /* These are the machine dependent pseudo-ops.
  200.  
  201.    This table describes all the machine specific pseudo-ops the assembler
  202.    has to support.  The fields are:
  203.         pseudo-op name without dot
  204.         function to call to execute this pseudo-op
  205.         integer arg to pass to the function
  206.  */
  207. #define S_LEAFPROC    1
  208. #define S_SYSPROC    2
  209.  
  210. const pseudo_typeS md_pseudo_table[] =
  211. {
  212.   {"bss", s_lcomm, 1},
  213.   {"endian", s_endian, 0},
  214.   {"extended", float_cons, 't'},
  215.   {"leafproc", parse_po, S_LEAFPROC},
  216.   {"sysproc", parse_po, S_SYSPROC},
  217.  
  218.   {"word", cons, 4},
  219.   {"quad", cons, 16},
  220.  
  221.   {0, 0, 0}
  222. };
  223.  
  224. /* Macros to extract info from an 'expressionS' structure 'e' */
  225. #define adds(e)    e.X_add_symbol
  226. #define offs(e)    e.X_add_number
  227.  
  228.  
  229. /* Branch-prediction bits for CTRL/COBR format opcodes */
  230. #define BP_MASK        0x00000002    /* Mask for branch-prediction bit */
  231. #define BP_TAKEN    0x00000000    /* Value to OR in to predict branch */
  232. #define BP_NOT_TAKEN    0x00000002    /* Value to OR in to predict no branch */
  233.  
  234.  
  235. /* Some instruction opcodes that we need explicitly */
  236. #define BE    0x12000000
  237. #define BG    0x11000000
  238. #define BGE    0x13000000
  239. #define BL    0x14000000
  240. #define BLE    0x16000000
  241. #define BNE    0x15000000
  242. #define BNO    0x10000000
  243. #define BO    0x17000000
  244. #define CHKBIT    0x5a002700
  245. #define CMPI    0x5a002080
  246. #define CMPO    0x5a002000
  247.  
  248. #define B    0x08000000
  249. #define BAL    0x0b000000
  250. #define CALL    0x09000000
  251. #define CALLS    0x66003800
  252. #define RET    0x0a000000
  253.  
  254.  
  255. /* These masks are used to build up a set of MEMB mode bits. */
  256. #define    A_BIT        0x0400
  257. #define    I_BIT        0x0800
  258. #define MEMB_BIT    0x1000
  259. #define    D_BIT        0x2000
  260.  
  261.  
  262. /* Mask for the only mode bit in a MEMA instruction (if set, abase reg is
  263.    used).  */
  264. #define MEMA_ABASE    0x2000
  265.  
  266. /* Info from which a MEMA or MEMB format instruction can be generated */
  267. typedef struct
  268.   {
  269.     /* (First) 32 bits of instruction */
  270.     long opcode;
  271.     /* 0-(none), 12- or, 32-bit displacement needed */
  272.     int disp;
  273.     /* The expression in the source instruction from which the
  274.        displacement should be determined.  */
  275.     char *e;
  276.   }
  277.  
  278. memS;
  279.  
  280.  
  281. /* The two pieces of info we need to generate a register operand */
  282. struct regop
  283.   {
  284.     int mode;            /* 0 =>local/global/spec reg; 1=> literal or fp reg */
  285.     int special;        /* 0 =>not a sfr;  1=> is a sfr (not valid w/mode=0) */
  286.     int n;            /* Register number or literal value */
  287.   };
  288.  
  289.  
  290. /* Number and assembler mnemonic for all registers that can appear in
  291.    operands.  */
  292. static const struct
  293.   {
  294.     char *reg_name;
  295.     int reg_num;
  296.   }
  297. regnames[] =
  298. {
  299.   { "pfp", 0 },
  300.   { "sp", 1 },
  301.   { "rip", 2 },
  302.   { "r3", 3 },
  303.   { "r4", 4 },
  304.   { "r5", 5 },
  305.   { "r6", 6 },
  306.   { "r7", 7 },
  307.   { "r8", 8 },
  308.   { "r9", 9 },
  309.   { "r10", 10 },
  310.   { "r11", 11 },
  311.   { "r12", 12 },
  312.   { "r13", 13 },
  313.   { "r14", 14 },
  314.   { "r15", 15 },
  315.   { "g0", 16 },
  316.   { "g1", 17 },
  317.   { "g2", 18 },
  318.   { "g3", 19 },
  319.   { "g4", 20 },
  320.   { "g5", 21 },
  321.   { "g6", 22 },
  322.   { "g7", 23 },
  323.   { "g8", 24 },
  324.   { "g9", 25 },
  325.   { "g10", 26 },
  326.   { "g11", 27 },
  327.   { "g12", 28 },
  328.   { "g13", 29 },
  329.   { "g14", 30 },
  330.   { "fp", 31 },
  331.  
  332.   /* Numbers for special-function registers are for assembler internal
  333.      use only: they are scaled back to range [0-31] for binary output.  */
  334. #define SF0    32
  335.  
  336.   { "sf0", 32 },
  337.   { "sf1", 33 },
  338.   { "sf2", 34 },
  339.   { "sf3", 35 },
  340.   { "sf4", 36 },
  341.   { "sf5", 37 },
  342.   { "sf6", 38 },
  343.   { "sf7", 39 },
  344.   { "sf8", 40 },
  345.   { "sf9", 41 },
  346.   { "sf10", 42 },
  347.   { "sf11", 43 },
  348.   { "sf12", 44 },
  349.   { "sf13", 45 },
  350.   { "sf14", 46 },
  351.   { "sf15", 47 },
  352.   { "sf16", 48 },
  353.   { "sf17", 49 },
  354.   { "sf18", 50 },
  355.   { "sf19", 51 },
  356.   { "sf20", 52 },
  357.   { "sf21", 53 },
  358.   { "sf22", 54 },
  359.   { "sf23", 55 },
  360.   { "sf24", 56 },
  361.   { "sf25", 57 },
  362.   { "sf26", 58 },
  363.   { "sf27", 59 },
  364.   { "sf28", 60 },
  365.   { "sf29", 61 },
  366.   { "sf30", 62 },
  367.   { "sf31", 63 },
  368.  
  369.   /* Numbers for floating point registers are for assembler internal
  370.      use only: they are scaled back to [0-3] for binary output.  */
  371. #define FP0    64
  372.  
  373.   { "fp0", 64 },
  374.   { "fp1", 65 },
  375.   { "fp2", 66 },
  376.   { "fp3", 67 },
  377.  
  378.   { NULL, 0 },                /* END OF LIST */
  379. };
  380.  
  381. #define    IS_RG_REG(n)    ((0 <= (n)) && ((n) < SF0))
  382. #define    IS_SF_REG(n)    ((SF0 <= (n)) && ((n) < FP0))
  383. #define    IS_FP_REG(n)    ((n) >= FP0)
  384.  
  385. /* Number and assembler mnemonic for all registers that can appear as
  386.    'abase' (indirect addressing) registers.  */
  387. static const struct
  388.   {
  389.     char *areg_name;
  390.     int areg_num;
  391.   }
  392. aregs[] =
  393. {
  394.   { "(pfp)", 0 },
  395.   { "(sp)", 1 },
  396.   { "(rip)", 2 },
  397.   { "(r3)", 3 },
  398.   { "(r4)", 4 },
  399.   { "(r5)", 5 },
  400.   { "(r6)", 6 },
  401.   { "(r7)", 7 },
  402.   { "(r8)", 8 },
  403.   { "(r9)", 9 },
  404.   { "(r10)", 10 },
  405.   { "(r11)", 11 },
  406.   { "(r12)", 12 },
  407.   { "(r13)", 13 },
  408.   { "(r14)", 14 },
  409.   { "(r15)", 15 },
  410.   { "(g0)", 16 },
  411.   { "(g1)", 17 },
  412.   { "(g2)", 18 },
  413.   { "(g3)", 19 },
  414.   { "(g4)", 20 },
  415.   { "(g5)", 21 },
  416.   { "(g6)", 22 },
  417.   { "(g7)", 23 },
  418.   { "(g8)", 24 },
  419.   { "(g9)", 25 },
  420.   { "(g10)", 26 },
  421.   { "(g11)", 27 },
  422.   { "(g12)", 28 },
  423.   { "(g13)", 29 },
  424.   { "(g14)", 30 },
  425.   { "(fp)", 31 },
  426.  
  427. #define IPREL    32
  428.   /* For assembler internal use only: this number never appears in binary
  429.      output.  */
  430.   { "(ip)", IPREL },
  431.  
  432.   { NULL, 0 },                /* END OF LIST */
  433. };
  434.  
  435.  
  436. /* Hash tables */
  437. static struct hash_control *op_hash;    /* Opcode mnemonics */
  438. static struct hash_control *reg_hash;    /* Register name hash table */
  439. static struct hash_control *areg_hash;    /* Abase register hash table */
  440.  
  441.  
  442. /* Architecture for which we are assembling */
  443. #define ARCH_ANY    0    /* Default: no architecture checking done */
  444. #define ARCH_KA        1
  445. #define ARCH_KB        2
  446. #define ARCH_MC        3
  447. #define ARCH_CA        4
  448. #define ARCH_JX        5
  449. #define ARCH_HX        6
  450. int architecture = ARCH_ANY;    /* Architecture requested on invocation line */
  451. int iclasses_seen;        /* OR of instruction classes (I_* constants)
  452.                  *    for which we've actually assembled
  453.                  *      instructions.
  454.                  */
  455.  
  456.  
  457. /* BRANCH-PREDICTION INSTRUMENTATION
  458.  
  459.         The following supports generation of branch-prediction instrumentation
  460.         (turned on by -b switch).  The instrumentation collects counts
  461.         of branches taken/not-taken for later input to a utility that will
  462.         set the branch prediction bits of the instructions in accordance with
  463.         the behavior observed.  (Note that the KX series does not have
  464.         brach-prediction.)
  465.  
  466.         The instrumentation consists of:
  467.  
  468.         (1) before and after each conditional branch, a call to an external
  469.             routine that increments and steps over an inline counter.  The
  470.             counter itself, initialized to 0, immediately follows the call
  471.             instruction.  For each branch, the counter following the branch
  472.             is the number of times the branch was not taken, and the difference
  473.             between the counters is the number of times it was taken.  An
  474.             example of an instrumented conditional branch:
  475.  
  476.                                 call    BR_CNT_FUNC
  477.                                 .word   0
  478.                 LBRANCH23:      be      label
  479.                                 call    BR_CNT_FUNC
  480.                                 .word   0
  481.  
  482.         (2) a table of pointers to the instrumented branches, so that an
  483.             external postprocessing routine can locate all of the counters.
  484.             the table begins with a 2-word header: a pointer to the next in
  485.             a linked list of such tables (initialized to 0);  and a count
  486.             of the number of entries in the table (exclusive of the header.
  487.  
  488.             Note that input source code is expected to already contain calls
  489.             an external routine that will link the branch local table into a
  490.             list of such tables.
  491.  */
  492.  
  493. /* Number of branches instrumented so far.  Also used to generate
  494.    unique local labels for each instrumented branch.  */
  495. static int br_cnt;
  496.  
  497. #define BR_LABEL_BASE    "LBRANCH"
  498. /* Basename of local labels on instrumented branches, to avoid
  499.    conflict with compiler- generated local labels.  */
  500.  
  501. #define BR_CNT_FUNC    "__inc_branch"
  502. /* Name of the external routine that will increment (and step over) an
  503.    inline counter.  */
  504.  
  505. #define BR_TAB_NAME    "__BRANCH_TABLE__"
  506. /* Name of the table of pointers to branches.  A local (i.e.,
  507.    non-external) symbol.  */
  508.  
  509. /*****************************************************************************
  510.    md_begin:  One-time initialization.
  511.  
  512.       Set up hash tables.
  513.  
  514.   *************************************************************************** */
  515. void
  516. md_begin ()
  517. {
  518.   int i;            /* Loop counter */
  519.   const struct i960_opcode *oP;    /* Pointer into opcode table */
  520.   const char *retval;        /* Value returned by hash functions */
  521.  
  522.   op_hash = hash_new ();
  523.   reg_hash = hash_new ();
  524.   areg_hash = hash_new ();
  525.  
  526.   /* For some reason, the base assembler uses an empty string for "no
  527.      error message", instead of a NULL pointer.  */
  528.   retval = 0;
  529.  
  530.   for (oP = i960_opcodes; oP->name && !retval; oP++)
  531.     retval = hash_insert (op_hash, oP->name, (PTR) oP);
  532.  
  533.   for (i = 0; regnames[i].reg_name && !retval; i++)
  534.     retval = hash_insert (reg_hash, regnames[i].reg_name,
  535.               (char *) ®names[i].reg_num);
  536.  
  537.   for (i = 0; aregs[i].areg_name && !retval; i++)
  538.     retval = hash_insert (areg_hash, aregs[i].areg_name,
  539.               (char *) &aregs[i].areg_num);
  540.  
  541.   if (retval)
  542.     as_fatal ("Hashing returned \"%s\".", retval);
  543. }
  544.  
  545. /*****************************************************************************
  546.    md_assemble:  Assemble an instruction
  547.  
  548.    Assumptions about the passed-in text:
  549.       - all comments, labels removed
  550.       - text is an instruction
  551.       - all white space compressed to single blanks
  552.       - all character constants have been replaced with decimal
  553.  
  554.   *************************************************************************** */
  555. void
  556. md_assemble (textP)
  557.      char *textP;        /* Source text of instruction */
  558. {
  559.   /* Parsed instruction text, containing NO whitespace: arg[0]->opcode
  560.      mnemonic arg[1-3]->operands, with char constants replaced by
  561.      decimal numbers.  */
  562.   char *args[4];
  563.  
  564.   int n_ops;            /* Number of instruction operands */
  565.   /* Pointer to instruction description */
  566.   struct i960_opcode *oP;
  567.   /* TRUE iff opcode mnemonic included branch-prediction suffix (".f"
  568.      or ".t").  */
  569.   int branch_predict;
  570.   /* Setting of branch-prediction bit(s) to be OR'd into instruction
  571.      opcode of CTRL/COBR format instructions.  */
  572.   long bp_bits;
  573.  
  574.   int n;            /* Offset of last character in opcode mnemonic */
  575.  
  576.   static const char bp_error_msg[] = "branch prediction invalid on this opcode";
  577.  
  578.  
  579.   /* Parse instruction into opcode and operands */
  580.   memset (args, '\0', sizeof (args));
  581.   n_ops = i_scan (textP, args);
  582.   if (n_ops == -1)
  583.     {
  584.       return;            /* Error message already issued */
  585.     }
  586.  
  587.   /* Do "macro substitution" (sort of) on 'ldconst' pseudo-instruction */
  588.   if (!strcmp (args[0], "ldconst"))
  589.     {
  590.       n_ops = parse_ldconst (args);
  591.       if (n_ops == -1)
  592.     {
  593.       return;
  594.     }
  595.     }
  596.  
  597.  
  598.  
  599.   /* Check for branch-prediction suffix on opcode mnemonic, strip it off */
  600.   n = strlen (args[0]) - 1;
  601.   branch_predict = 0;
  602.   bp_bits = 0;
  603.   if (args[0][n - 1] == '.' && (args[0][n] == 't' || args[0][n] == 'f'))
  604.     {
  605.       /* We could check here to see if the target architecture
  606.      supports branch prediction, but why bother?  The bit will
  607.      just be ignored by processors that don't use it.  */
  608.       branch_predict = 1;
  609.       bp_bits = (args[0][n] == 't') ? BP_TAKEN : BP_NOT_TAKEN;
  610.       args[0][n - 1] = '\0';    /* Strip suffix from opcode mnemonic */
  611.     }
  612.  
  613.   /* Look up opcode mnemonic in table and check number of operands.
  614.      Check that opcode is legal for the target architecture.  If all
  615.      looks good, assemble instruction.  */
  616.   oP = (struct i960_opcode *) hash_find (op_hash, args[0]);
  617.   if (!oP || !targ_has_iclass (oP->iclass))
  618.     {
  619.       as_bad ("invalid opcode, \"%s\".", args[0]);
  620.  
  621.     }
  622.   else if (n_ops != oP->num_ops)
  623.     {
  624.       as_bad ("improper number of operands.  expecting %d, got %d",
  625.           oP->num_ops, n_ops);
  626.     }
  627.   else
  628.     {
  629.       switch (oP->format)
  630.     {
  631.     case FBRA:
  632.     case CTRL:
  633.       ctrl_fmt (args[1], oP->opcode | bp_bits, oP->num_ops);
  634.       if (oP->format == FBRA)
  635.         {
  636.           /* Now generate a 'bno' to same arg */
  637.           ctrl_fmt (args[1], BNO | bp_bits, 1);
  638.         }
  639.       break;
  640.     case COBR:
  641.     case COJ:
  642.       cobr_fmt (args, oP->opcode | bp_bits, oP);
  643.       break;
  644.     case REG:
  645.       if (branch_predict)
  646.         {
  647.           as_warn (bp_error_msg);
  648.         }
  649.       reg_fmt (args, oP);
  650.       break;
  651.     case MEM1:
  652.       if (args[0][0] == 'c' && args[0][1] == 'a')
  653.         {
  654.           if (branch_predict)
  655.         {
  656.           as_warn (bp_error_msg);
  657.         }
  658.           mem_fmt (args, oP, 1);
  659.           break;
  660.         }
  661.     case MEM2:
  662.     case MEM4:
  663.     case MEM8:
  664.     case MEM12:
  665.     case MEM16:
  666.       if (branch_predict)
  667.         {
  668.           as_warn (bp_error_msg);
  669.         }
  670.       mem_fmt (args, oP, 0);
  671.       break;
  672.     case CALLJ:
  673.       if (branch_predict)
  674.         {
  675.           as_warn (bp_error_msg);
  676.         }
  677.       /* Output opcode & set up "fixup" (relocation); flag
  678.          relocation as 'callj' type.  */
  679.       know (oP->num_ops == 1);
  680.       get_cdisp (args[1], "CTRL", oP->opcode, 24, 0, 1);
  681.       break;
  682.     default:
  683.       BAD_CASE (oP->format);
  684.       break;
  685.     }
  686.     }
  687. }                /* md_assemble() */
  688.  
  689. /*****************************************************************************
  690.    md_number_to_chars:  convert a number to target byte order
  691.  
  692.   *************************************************************************** */
  693. void
  694. md_number_to_chars (buf, value, n)
  695.      char *buf;
  696.      valueT value;
  697.      int n;
  698. {
  699.   number_to_chars_littleendian (buf, value, n);
  700. }
  701.  
  702. /*****************************************************************************
  703.    md_chars_to_number:  convert from target byte order to host byte order.
  704.  
  705.   *************************************************************************** */
  706. int
  707. md_chars_to_number (val, n)
  708.      unsigned char *val;    /* Value in target byte order */
  709.      int n;            /* Number of bytes in the input */
  710. {
  711.   int retval;
  712.  
  713.   for (retval = 0; n--;)
  714.     {
  715.       retval <<= 8;
  716.       retval |= val[n];
  717.     }
  718.   return retval;
  719. }
  720.  
  721.  
  722. #define MAX_LITTLENUMS    6
  723. #define LNUM_SIZE    sizeof(LITTLENUM_TYPE)
  724.  
  725. /*****************************************************************************
  726.    md_atof:    convert ascii to floating point
  727.  
  728.    Turn a string at input_line_pointer into a floating point constant of type
  729.    'type', and store the appropriate bytes at *litP.  The number of LITTLENUMS
  730.    emitted is returned at 'sizeP'.  An error message is returned, or a pointer
  731.    to an empty message if OK.
  732.  
  733.    Note we call the i386 floating point routine, rather than complicating
  734.    things with more files or symbolic links.
  735.  
  736.   *************************************************************************** */
  737. char *
  738. md_atof (type, litP, sizeP)
  739.      int type;
  740.      char *litP;
  741.      int *sizeP;
  742. {
  743.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  744.   LITTLENUM_TYPE *wordP;
  745.   int prec;
  746.   char *t;
  747.   char *atof_ieee ();
  748.  
  749.   switch (type)
  750.     {
  751.     case 'f':
  752.     case 'F':
  753.       prec = 2;
  754.       break;
  755.  
  756.     case 'd':
  757.     case 'D':
  758.       prec = 4;
  759.       break;
  760.  
  761.     case 't':
  762.     case 'T':
  763.       prec = 5;
  764.       type = 'x';        /* That's what atof_ieee() understands */
  765.       break;
  766.  
  767.     default:
  768.       *sizeP = 0;
  769.       return "Bad call to md_atof()";
  770.     }
  771.  
  772.   t = atof_ieee (input_line_pointer, type, words);
  773.   if (t)
  774.     {
  775.       input_line_pointer = t;
  776.     }
  777.  
  778.   *sizeP = prec * LNUM_SIZE;
  779.  
  780.   /* Output the LITTLENUMs in REVERSE order in accord with i80960
  781.      word-order.  (Dunno why atof_ieee doesn't do it in the right
  782.      order in the first place -- probably because it's a hack of
  783.      atof_m68k.)  */
  784.  
  785.   for (wordP = words + prec - 1; prec--;)
  786.     {
  787.       md_number_to_chars (litP, (long) (*wordP--), LNUM_SIZE);
  788.       litP += sizeof (LITTLENUM_TYPE);
  789.     }
  790.  
  791.   return 0;
  792. }
  793.  
  794.  
  795. /*****************************************************************************
  796.    md_number_to_imm
  797.  
  798.   *************************************************************************** */
  799. void
  800. md_number_to_imm (buf, val, n)
  801.      char *buf;
  802.      long val;
  803.      int n;
  804. {
  805.   md_number_to_chars (buf, val, n);
  806. }
  807.  
  808.  
  809. /*****************************************************************************
  810.    md_number_to_disp
  811.  
  812.   *************************************************************************** */
  813. void
  814. md_number_to_disp (buf, val, n)
  815.      char *buf;
  816.      long val;
  817.      int n;
  818. {
  819.   md_number_to_chars (buf, val, n);
  820. }
  821.  
  822. /*****************************************************************************
  823.    md_number_to_field:
  824.  
  825.       Stick a value (an address fixup) into a bit field of
  826.       previously-generated instruction.
  827.  
  828.   *************************************************************************** */
  829. void
  830. md_number_to_field (instrP, val, bfixP)
  831.      char *instrP;        /* Pointer to instruction to be fixed */
  832.      long val;            /* Address fixup value */
  833.      bit_fixS *bfixP;        /* Description of bit field to be fixed up */
  834. {
  835.   int numbits;            /* Length of bit field to be fixed */
  836.   long instr;            /* 32-bit instruction to be fixed-up */
  837.   long sign;            /* 0 or -1, according to sign bit of 'val' */
  838.  
  839.   /* Convert instruction back to host byte order.  */
  840.   instr = md_chars_to_number (instrP, 4);
  841.  
  842.   /* Surprise! -- we stored the number of bits to be modified rather
  843.      than a pointer to a structure.  */
  844.   numbits = (int) bfixP;
  845.   if (numbits == 1)
  846.     {
  847.       /* This is a no-op, stuck here by reloc_callj() */
  848.       return;
  849.     }
  850.  
  851.   know ((numbits == 13) || (numbits == 24));
  852.  
  853.   /* Propagate sign bit of 'val' for the given number of bits.  Result
  854.      should be all 0 or all 1.  */
  855.   sign = val >> ((int) numbits - 1);
  856.   if (((val < 0) && (sign != -1))
  857.       || ((val > 0) && (sign != 0)))
  858.     {
  859.       as_bad ("Fixup of %ld too large for field width of %d",
  860.           val, numbits);
  861.     }
  862.   else
  863.     {
  864.       /* Put bit field into instruction and write back in target
  865.          * byte order.
  866.        */
  867.       val &= ~(-1 << (int) numbits);    /* Clear unused sign bits */
  868.       instr |= val;
  869.       md_number_to_chars (instrP, instr, 4);
  870.     }
  871. }                /* md_number_to_field() */
  872.  
  873.  
  874. /*****************************************************************************
  875.    md_parse_option
  876.       Invocation line includes a switch not recognized by the base assembler.
  877.       See if it's a processor-specific option.  For the 960, these are:
  878.  
  879.       -norelax:
  880.           Conditional branch instructions that require displacements
  881.           greater than 13 bits (or that have external targets) should
  882.           generate errors.  The default is to replace each such
  883.           instruction with the corresponding compare (or chkbit) and
  884.           branch instructions.  Note that the Intel "j" cobr directives
  885.           are ALWAYS "de-optimized" in this way when necessary,
  886.           regardless of the setting of this option.
  887.  
  888.       -b:
  889.           Add code to collect information about branches taken, for
  890.           later optimization of branch prediction bits by a separate
  891.           tool.  COBR and CNTL format instructions have branch
  892.           prediction bits (in the CX architecture);  if "BR" represents
  893.           an instruction in one of these classes, the following rep-
  894.           resents the code generated by the assembler:
  895.  
  896.               call    <increment routine>
  897.               .word    0    # pre-counter
  898.           Label:  BR
  899.               call    <increment routine>
  900.               .word    0    # post-counter
  901.  
  902.           A table of all such "Labels" is also generated.
  903.  
  904.  
  905.       -AKA, -AKB, -AKC, -ASA, -ASB, -AMC, -ACA:
  906.           Select the 80960 architecture.  Instructions or features not
  907.           supported by the selected architecture cause fatal errors.
  908.           The default is to generate code for any instruction or feature
  909.           that is supported by SOME version of the 960 (even if this
  910.           means mixing architectures!).
  911.  
  912.   ****************************************************************************/
  913.  
  914. CONST char *md_shortopts = "A:b";
  915. struct option md_longopts[] =
  916. {
  917. #define OPTION_LINKRELAX (OPTION_MD_BASE)
  918.   {"linkrelax", no_argument, NULL, OPTION_LINKRELAX},
  919.   {"link-relax", no_argument, NULL, OPTION_LINKRELAX},
  920. #define OPTION_NORELAX (OPTION_MD_BASE + 1)
  921.   {"norelax", no_argument, NULL, OPTION_NORELAX},
  922.   {"no-relax", no_argument, NULL, OPTION_NORELAX},
  923.   {NULL, no_argument, NULL, 0}
  924. };
  925. size_t md_longopts_size = sizeof (md_longopts);
  926.  
  927. struct tabentry
  928.   {
  929.     char *flag;
  930.     int arch;
  931.   };
  932. static const struct tabentry arch_tab[] =
  933. {
  934.   {"KA", ARCH_KA},
  935.   {"KB", ARCH_KB},
  936.   {"SA", ARCH_KA},        /* Synonym for KA */
  937.   {"SB", ARCH_KB},        /* Synonym for KB */
  938.   {"KC", ARCH_MC},        /* Synonym for MC */
  939.   {"MC", ARCH_MC},
  940.   {"CA", ARCH_CA},
  941.   {"JX", ARCH_JX},
  942.   {"HX", ARCH_HX},
  943.   {NULL, 0}
  944. };
  945.  
  946. int
  947. md_parse_option (c, arg)
  948.      int c;
  949.      char *arg;
  950. {
  951.   switch (c)
  952.     {
  953.     case OPTION_LINKRELAX:
  954.       linkrelax = 1;
  955.       flag_keep_locals = 1;
  956.       break;
  957.  
  958.     case OPTION_NORELAX:
  959.       norelax = 1;
  960.       break;
  961.  
  962.     case 'b':
  963.       instrument_branches = 1;
  964.       break;
  965.  
  966.     case 'A':
  967.       {
  968.     const struct tabentry *tp;
  969.     char *p = arg;
  970.  
  971.     for (tp = arch_tab; tp->flag != NULL; tp++)
  972.       if (!strcmp (p, tp->flag))
  973.         break;
  974.  
  975.     if (tp->flag == NULL)
  976.       {
  977.         as_bad ("invalid architecture %s", p);
  978.         return 0;
  979.       }
  980.     else
  981.       architecture = tp->arch;
  982.       }
  983.       break;
  984.  
  985.     default:
  986.       return 0;
  987.     }
  988.  
  989.   return 1;
  990. }
  991.  
  992. void
  993. md_show_usage (stream)
  994.      FILE *stream;
  995. {
  996.   int i;
  997.   fprintf (stream, "I960 options:\n");
  998.   for (i = 0; arch_tab[i].flag; i++)
  999.     fprintf (stream, "%s-A%s", i ? " | " : "", arch_tab[i].flag);
  1000.   fprintf (stream, "\n\
  1001.             specify variant of 960 architecture\n\
  1002. -b            add code to collect statistics about branches taken\n\
  1003. -link-relax        preserve individual alignment directives so linker\n\
  1004.             can do relaxing (b.out format only)\n\
  1005. -no-relax        don't alter compare-and-branch instructions for\n\
  1006.             long displacements\n");
  1007. }
  1008.  
  1009.  
  1010. #ifndef BFD_ASSEMBLER
  1011. /*****************************************************************************
  1012.    md_convert_frag:
  1013.       Called by base assembler after address relaxation is finished:  modify
  1014.       variable fragments according to how much relaxation was done.
  1015.  
  1016.       If the fragment substate is still 1, a 13-bit displacement was enough
  1017.       to reach the symbol in question.  Set up an address fixup, but otherwise
  1018.       leave the cobr instruction alone.
  1019.  
  1020.       If the fragment substate is 2, a 13-bit displacement was not enough.
  1021.       Replace the cobr with a two instructions (a compare and a branch).
  1022.  
  1023.   *************************************************************************** */
  1024. void
  1025. md_convert_frag (headers, seg, fragP)
  1026.      object_headers *headers;
  1027.      segT seg;
  1028.      fragS *fragP;
  1029. {
  1030.   fixS *fixP;            /* Structure describing needed address fix */
  1031.  
  1032.   switch (fragP->fr_subtype)
  1033.     {
  1034.     case 1:
  1035.       /* LEAVE SINGLE COBR INSTRUCTION */
  1036.       fixP = fix_new (fragP,
  1037.               fragP->fr_opcode - fragP->fr_literal,
  1038.               4,
  1039.               fragP->fr_symbol,
  1040.               fragP->fr_offset,
  1041.               1,
  1042.               NO_RELOC);
  1043.  
  1044.       fixP->fx_bit_fixP = (bit_fixS *) 13;    /* size of bit field */
  1045.       break;
  1046.     case 2:
  1047.       /* REPLACE COBR WITH COMPARE/BRANCH INSTRUCTIONS */
  1048.       relax_cobr (fragP);
  1049.       break;
  1050.     default:
  1051.       BAD_CASE (fragP->fr_subtype);
  1052.       break;
  1053.     }
  1054. }
  1055.  
  1056. /*****************************************************************************
  1057.    md_estimate_size_before_relax:  How much does it look like *fragP will grow?
  1058.  
  1059.       Called by base assembler just before address relaxation.
  1060.       Return the amount by which the fragment will grow.
  1061.  
  1062.       Any symbol that is now undefined will not become defined; cobr's
  1063.       based on undefined symbols will have to be replaced with a compare
  1064.       instruction and a branch instruction, and the code fragment will grow
  1065.       by 4 bytes.
  1066.  
  1067.   *************************************************************************** */
  1068. int
  1069. md_estimate_size_before_relax (fragP, segment_type)
  1070.      register fragS *fragP;
  1071.      register segT segment_type;
  1072. {
  1073.   /* If symbol is undefined in this segment, go to "relaxed" state
  1074.      (compare and branch instructions instead of cobr) right now.  */
  1075.   if (S_GET_SEGMENT (fragP->fr_symbol) != segment_type)
  1076.     {
  1077.       relax_cobr (fragP);
  1078.       return 4;
  1079.     }
  1080.   return 0;
  1081. }                /* md_estimate_size_before_relax() */
  1082.  
  1083.  
  1084. /*****************************************************************************
  1085.    md_ri_to_chars:
  1086.       This routine exists in order to overcome machine byte-order problems
  1087.       when dealing with bit-field entries in the relocation_info struct.
  1088.  
  1089.       But relocation info will be used on the host machine only (only
  1090.       executable code is actually downloaded to the i80960).  Therefore,
  1091.       we leave it in host byte order.
  1092.  
  1093.       The above comment is no longer true.  This routine now really
  1094.       does do the reordering (Ian Taylor 28 Aug 92).
  1095.  
  1096.   *************************************************************************** */
  1097. void
  1098. md_ri_to_chars (where, ri)
  1099.      char *where;
  1100.      struct relocation_info *ri;
  1101. {
  1102.   md_number_to_chars (where, ri->r_address,
  1103.               sizeof (ri->r_address));
  1104.   where[4] = ri->r_index & 0x0ff;
  1105.   where[5] = (ri->r_index >> 8) & 0x0ff;
  1106.   where[6] = (ri->r_index >> 16) & 0x0ff;
  1107.   where[7] = ((ri->r_pcrel << 0)
  1108.           | (ri->r_length << 1)
  1109.           | (ri->r_extern << 3)
  1110.           | (ri->r_bsr << 4)
  1111.           | (ri->r_disp << 5)
  1112.           | (ri->r_callj << 6));
  1113. }
  1114.  
  1115. #ifndef WORKING_DOT_WORD
  1116.  
  1117. int md_short_jump_size = 0;
  1118. int md_long_jump_size = 0;
  1119.  
  1120. void
  1121. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1122.      char *ptr;
  1123.      addressT from_addr;
  1124.      addressT to_addr;
  1125.      fragS *frag;
  1126.      symbolS *to_symbol;
  1127. {
  1128.   as_fatal ("failed sanity check.");
  1129. }
  1130.  
  1131. void
  1132. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1133.      char *ptr;
  1134.      addressT from_addr, to_addr;
  1135.      fragS *frag;
  1136.      symbolS *to_symbol;
  1137. {
  1138.   as_fatal ("failed sanity check.");
  1139. }
  1140.  
  1141. #endif
  1142. #endif /* BFD_ASSEMBLER */
  1143.  
  1144. /* FOLLOWING ARE THE LOCAL ROUTINES, IN ALPHABETICAL ORDER  */
  1145.  
  1146. /*****************************************************************************
  1147.    brcnt_emit:    Emit code to increment inline branch counter.
  1148.  
  1149.       See the comments above the declaration of 'br_cnt' for details on
  1150.       branch-prediction instrumentation.
  1151.   *************************************************************************** */
  1152. static void
  1153. brcnt_emit ()
  1154. {
  1155.   ctrl_fmt (BR_CNT_FUNC, CALL, 1);    /* Emit call to "increment" routine */
  1156.   emit (0);            /* Emit inline counter to be incremented */
  1157. }
  1158.  
  1159. /*****************************************************************************
  1160.    brlab_next:    generate the next branch local label
  1161.  
  1162.       See the comments above the declaration of 'br_cnt' for details on
  1163.       branch-prediction instrumentation.
  1164.   *************************************************************************** */
  1165. static char *
  1166. brlab_next ()
  1167. {
  1168.   static char buf[20];
  1169.  
  1170.   sprintf (buf, "%s%d", BR_LABEL_BASE, br_cnt++);
  1171.   return buf;
  1172. }
  1173.  
  1174. /*****************************************************************************
  1175.    brtab_emit:    generate the fetch-prediction branch table.
  1176.  
  1177.       See the comments above the declaration of 'br_cnt' for details on
  1178.       branch-prediction instrumentation.
  1179.  
  1180.       The code emitted here would be functionally equivalent to the following
  1181.       example assembler source.
  1182.  
  1183.               .data
  1184.               .align    2
  1185.          BR_TAB_NAME:
  1186.               .word    0        # link to next table
  1187.               .word    3        # length of table
  1188.               .word    LBRANCH0    # 1st entry in table proper
  1189.               .word    LBRANCH1
  1190.               .word    LBRANCH2
  1191.   **************************************************************************** */
  1192. void
  1193. brtab_emit ()
  1194. {
  1195.   int i;
  1196.   char buf[20];
  1197.   char *p;            /* Where the binary was output to */
  1198.   /* Pointer to description of deferred address fixup.  */
  1199.   fixS *fixP;
  1200.  
  1201.   if (!instrument_branches)
  1202.     {
  1203.       return;
  1204.     }
  1205.  
  1206.   subseg_set (data_section, 0);    /*      .data */
  1207.   frag_align (2, 0);        /*      .align 2 */
  1208.   record_alignment (now_seg, 2);
  1209.   colon (BR_TAB_NAME);        /* BR_TAB_NAME: */
  1210.   emit (0);            /*      .word 0 #link to next table */
  1211.   emit (br_cnt);        /*      .word n #length of table */
  1212.  
  1213.   for (i = 0; i < br_cnt; i++)
  1214.     {
  1215.       sprintf (buf, "%s%d", BR_LABEL_BASE, i);
  1216.       p = emit (0);
  1217.       fixP = fix_new (frag_now,
  1218.               p - frag_now->fr_literal,
  1219.               4,
  1220.               symbol_find (buf),
  1221.               0,
  1222.               0,
  1223.               NO_RELOC);
  1224.     }
  1225. }
  1226.  
  1227. /*****************************************************************************
  1228.    cobr_fmt:    generate a COBR-format instruction
  1229.  
  1230.   *************************************************************************** */
  1231. static
  1232. void
  1233. cobr_fmt (arg, opcode, oP)
  1234.      /* arg[0]->opcode mnemonic, arg[1-3]->operands (ascii) */
  1235.      char *arg[];
  1236.      /* Opcode, with branch-prediction bits already set if necessary.  */
  1237.      long opcode;
  1238.      /* Pointer to description of instruction.  */
  1239.      struct i960_opcode *oP;
  1240. {
  1241.   long instr;            /* 32-bit instruction */
  1242.   struct regop regop;        /* Description of register operand */
  1243.   int n;            /* Number of operands */
  1244.   int var_frag;            /* 1 if varying length code fragment should
  1245.                  *    be emitted;  0 if an address fix
  1246.                  *      should be emitted.
  1247.                  */
  1248.  
  1249.   instr = opcode;
  1250.   n = oP->num_ops;
  1251.  
  1252.   if (n >= 1)
  1253.     {
  1254.       /* First operand (if any) of a COBR is always a register
  1255.      operand.  Parse it.  */
  1256.       parse_regop (®op, arg[1], oP->operand[0]);
  1257.       instr |= (regop.n << 19) | (regop.mode << 13);
  1258.     }
  1259.   if (n >= 2)
  1260.     {
  1261.       /* Second operand (if any) of a COBR is always a register
  1262.      operand.  Parse it.  */
  1263.     parse_regop (®op, arg[2], oP->operand[1]);
  1264.       instr |= (regop.n << 14) | regop.special;
  1265.     }
  1266.  
  1267.  
  1268.   if (n < 3)
  1269.     {
  1270.       emit (instr);
  1271.  
  1272.     }
  1273.   else
  1274.     {
  1275.       if (instrument_branches)
  1276.     {
  1277.       brcnt_emit ();
  1278.       colon (brlab_next ());
  1279.     }
  1280.  
  1281.       /* A third operand to a COBR is always a displacement.  Parse
  1282.          it; if it's relaxable (a cobr "j" directive, or any cobr
  1283.          other than bbs/bbc when the "-norelax" option is not in use)
  1284.          set up a variable code fragment; otherwise set up an address
  1285.          fix.  */
  1286.       var_frag = !norelax || (oP->format == COJ);    /* TRUE or FALSE */
  1287.       get_cdisp (arg[3], "COBR", instr, 13, var_frag, 0);
  1288.  
  1289.       if (instrument_branches)
  1290.     {
  1291.       brcnt_emit ();
  1292.     }
  1293.     }
  1294. }                /* cobr_fmt() */
  1295.  
  1296.  
  1297. /*****************************************************************************
  1298.    ctrl_fmt:    generate a CTRL-format instruction
  1299.  
  1300.   *************************************************************************** */
  1301. static
  1302. void
  1303. ctrl_fmt (targP, opcode, num_ops)
  1304.      char *targP;        /* Pointer to text of lone operand (if any) */
  1305.      long opcode;        /* Template of instruction */
  1306.      int num_ops;        /* Number of operands */
  1307. {
  1308.   int instrument;        /* TRUE iff we should add instrumentation to track
  1309.                    * how often the branch is taken
  1310.                  */
  1311.  
  1312.  
  1313.   if (num_ops == 0)
  1314.     {
  1315.       emit (opcode);        /* Output opcode */
  1316.     }
  1317.   else
  1318.     {
  1319.  
  1320.       instrument = instrument_branches && (opcode != CALL)
  1321.     && (opcode != B) && (opcode != RET) && (opcode != BAL);
  1322.  
  1323.       if (instrument)
  1324.     {
  1325.       brcnt_emit ();
  1326.       colon (brlab_next ());
  1327.     }
  1328.  
  1329.       /* The operand MUST be an ip-relative displacment. Parse it
  1330.          * and set up address fix for the instruction we just output.
  1331.        */
  1332.       get_cdisp (targP, "CTRL", opcode, 24, 0, 0);
  1333.  
  1334.       if (instrument)
  1335.     {
  1336.       brcnt_emit ();
  1337.     }
  1338.     }
  1339.  
  1340. }
  1341.  
  1342.  
  1343. /*****************************************************************************
  1344.    emit:    output instruction binary
  1345.  
  1346.       Output instruction binary, in target byte order, 4 bytes at a time.
  1347.       Return pointer to where it was placed.
  1348.  
  1349.   *************************************************************************** */
  1350. static
  1351. char *
  1352. emit (instr)
  1353.      long instr;        /* Word to be output, host byte order */
  1354. {
  1355.   char *toP;            /* Where to output it */
  1356.  
  1357.   toP = frag_more (4);        /* Allocate storage */
  1358.   md_number_to_chars (toP, instr, 4);    /* Convert to target byte order */
  1359.   return toP;
  1360. }
  1361.  
  1362.  
  1363. /*****************************************************************************
  1364.    get_args:    break individual arguments out of comma-separated list
  1365.  
  1366.    Input assumptions:
  1367.       - all comments and labels have been removed
  1368.       - all strings of whitespace have been collapsed to a single blank.
  1369.       - all character constants ('x') have been replaced with decimal
  1370.  
  1371.    Output:
  1372.       args[0] is untouched. args[1] points to first operand, etc. All args:
  1373.       - are NULL-terminated
  1374.       - contain no whitespace
  1375.  
  1376.    Return value:
  1377.       Number of operands (0,1,2, or 3) or -1 on error.
  1378.  
  1379.   *************************************************************************** */
  1380. static int
  1381. get_args (p, args)
  1382.      /* Pointer to comma-separated operands; MUCKED BY US */
  1383.      register char *p;
  1384.      /* Output arg: pointers to operands placed in args[1-3].  MUST
  1385.         ACCOMMODATE 4 ENTRIES (args[0-3]).  */
  1386.      char *args[];
  1387. {
  1388.   register int n;        /* Number of operands */
  1389.   register char *to;
  1390.  
  1391.   /* Skip lead white space */
  1392.   while (*p == ' ')
  1393.     {
  1394.       p++;
  1395.     }
  1396.  
  1397.   if (*p == '\0')
  1398.     {
  1399.       return 0;
  1400.     }
  1401.  
  1402.   n = 1;
  1403.   args[1] = p;
  1404.  
  1405.   /* Squeze blanks out by moving non-blanks toward start of string.
  1406.      * Isolate operands, whenever comma is found.
  1407.    */
  1408.   to = p;
  1409.   while (*p != '\0')
  1410.     {
  1411.  
  1412.       if (*p == ' '
  1413.       && (! isalnum (p[1]) || ! isalnum (p[-1])))
  1414.     {
  1415.       p++;
  1416.  
  1417.     }
  1418.       else if (*p == ',')
  1419.     {
  1420.  
  1421.       /* Start of operand */
  1422.       if (n == 3)
  1423.         {
  1424.           as_bad ("too many operands");
  1425.           return -1;
  1426.         }
  1427.       *to++ = '\0';        /* Terminate argument */
  1428.       args[++n] = to;    /* Start next argument */
  1429.       p++;
  1430.  
  1431.     }
  1432.       else
  1433.     {
  1434.       *to++ = *p++;
  1435.     }
  1436.     }
  1437.   *to = '\0';
  1438.   return n;
  1439. }
  1440.  
  1441.  
  1442. /*****************************************************************************
  1443.    get_cdisp:    handle displacement for a COBR or CTRL instruction.
  1444.  
  1445.       Parse displacement for a COBR or CTRL instruction.
  1446.  
  1447.       If successful, output the instruction opcode and set up for it,
  1448.       depending on the arg 'var_frag', either:
  1449.           o an address fixup to be done when all symbol values are known, or
  1450.           o a varying length code fragment, with address fixup info.  This
  1451.           will be done for cobr instructions that may have to be relaxed
  1452.           in to compare/branch instructions (8 bytes) if the final
  1453.           address displacement is greater than 13 bits.
  1454.  
  1455.   ****************************************************************************/
  1456. static
  1457. void
  1458. get_cdisp (dispP, ifmtP, instr, numbits, var_frag, callj)
  1459.      /* displacement as specified in source instruction */
  1460.      char *dispP;
  1461.      /* "COBR" or "CTRL" (for use in error message) */
  1462.      char *ifmtP;
  1463.      /* Instruction needing the displacement */
  1464.      long instr;
  1465.      /* # bits of displacement (13 for COBR, 24 for CTRL) */
  1466.      int numbits;
  1467.      /* 1 if varying length code fragment should be emitted;
  1468.       *       0 if an address fix should be emitted.
  1469.       */
  1470.      int var_frag;
  1471.      /* 1 if callj relocation should be done; else 0 */
  1472.      int callj;
  1473. {
  1474.   expressionS e;        /* Parsed expression */
  1475.   fixS *fixP;            /* Structure describing needed address fix */
  1476.   char *outP;            /* Where instruction binary is output to */
  1477.  
  1478.   fixP = NULL;
  1479.  
  1480.   parse_expr (dispP, &e);
  1481.   switch (e.X_op)
  1482.     {
  1483.     case O_illegal:
  1484.       as_bad ("expression syntax error");
  1485.  
  1486.     case O_symbol:
  1487.       if (S_GET_SEGMENT (e.X_add_symbol) == now_seg
  1488.       || S_GET_SEGMENT (e.X_add_symbol) == undefined_section)
  1489.     {
  1490.       if (var_frag)
  1491.         {
  1492.           outP = frag_more (8);    /* Allocate worst-case storage */
  1493.           md_number_to_chars (outP, instr, 4);
  1494.           frag_variant (rs_machine_dependent, 4, 4, 1,
  1495.                 adds (e), offs (e), outP);
  1496.         }
  1497.       else
  1498.         {
  1499.           /* Set up a new fix structure, so address can be updated
  1500.            * when all symbol values are known.
  1501.            */
  1502.           outP = emit (instr);
  1503.           fixP = fix_new (frag_now,
  1504.                   outP - frag_now->fr_literal,
  1505.                   4,
  1506.                   adds (e),
  1507.                   offs (e),
  1508.                   1,
  1509.                   NO_RELOC);
  1510.  
  1511.           fixP->fx_tcbit = callj;
  1512.  
  1513.           /* We want to modify a bit field when the address is
  1514.            * known.  But we don't need all the garbage in the
  1515.            * bit_fix structure.  So we're going to lie and store
  1516.            * the number of bits affected instead of a pointer.
  1517.            */
  1518.           fixP->fx_bit_fixP = (bit_fixS *) numbits;
  1519.         }
  1520.     }
  1521.       else
  1522.     as_bad ("attempt to branch into different segment");
  1523.       break;
  1524.  
  1525.     default:
  1526.       as_bad ("target of %s instruction must be a label", ifmtP);
  1527.       break;
  1528.     }
  1529. }
  1530.  
  1531.  
  1532. /*****************************************************************************
  1533.    get_ispec:    parse a memory operand for an index specification
  1534.  
  1535.       Here, an "index specification" is taken to be anything surrounded
  1536.       by square brackets and NOT followed by anything else.
  1537.  
  1538.       If it's found, detach it from the input string, remove the surrounding
  1539.       square brackets, and return a pointer to it.  Otherwise, return NULL.
  1540.  
  1541.   *************************************************************************** */
  1542. static
  1543. char *
  1544. get_ispec (textP)
  1545.      /* Pointer to memory operand from source instruction, no white space.  */
  1546.      char *textP;
  1547. {
  1548.   /* Points to start of index specification.  */
  1549.   char *start;
  1550.   /* Points to end of index specification.  */
  1551.   char *end;
  1552.  
  1553.   /* Find opening square bracket, if any.  */
  1554.   start = strchr (textP, '[');
  1555.  
  1556.   if (start != NULL)
  1557.     {
  1558.  
  1559.       /* Eliminate '[', detach from rest of operand */
  1560.       *start++ = '\0';
  1561.  
  1562.       end = strchr (start, ']');
  1563.  
  1564.       if (end == NULL)
  1565.     {
  1566.       as_bad ("unmatched '['");
  1567.  
  1568.     }
  1569.       else
  1570.     {
  1571.       /* Eliminate ']' and make sure it was the last thing
  1572.          * in the string.
  1573.        */
  1574.       *end = '\0';
  1575.       if (*(end + 1) != '\0')
  1576.         {
  1577.           as_bad ("garbage after index spec ignored");
  1578.         }
  1579.     }
  1580.     }
  1581.   return start;
  1582. }
  1583.  
  1584. /*****************************************************************************
  1585.    get_regnum:
  1586.  
  1587.       Look up a (suspected) register name in the register table and return the
  1588.       associated register number (or -1 if not found).
  1589.  
  1590.   *************************************************************************** */
  1591. static
  1592. int
  1593. get_regnum (regname)
  1594.      char *regname;        /* Suspected register name */
  1595. {
  1596.   int *rP;
  1597.  
  1598.   rP = (int *) hash_find (reg_hash, regname);
  1599.   return (rP == NULL) ? -1 : *rP;
  1600. }
  1601.  
  1602.  
  1603. /*****************************************************************************
  1604.    i_scan:    perform lexical scan of ascii assembler instruction.
  1605.  
  1606.    Input assumptions:
  1607.       - input string is an i80960 instruction (not a pseudo-op)
  1608.       - all comments and labels have been removed
  1609.       - all strings of whitespace have been collapsed to a single blank.
  1610.  
  1611.    Output:
  1612.       args[0] points to opcode, other entries point to operands. All strings:
  1613.       - are NULL-terminated
  1614.       - contain no whitespace
  1615.       - have character constants ('x') replaced with a decimal number
  1616.  
  1617.    Return value:
  1618.       Number of operands (0,1,2, or 3) or -1 on error.
  1619.  
  1620.   *************************************************************************** */
  1621. static int
  1622. i_scan (iP, args)
  1623.      /* Pointer to ascii instruction;  MUCKED BY US. */
  1624.      register char *iP;
  1625.      /* Output arg: pointers to opcode and operands placed here.  MUST
  1626.     ACCOMMODATE 4 ENTRIES.  */
  1627.      char *args[];
  1628. {
  1629.  
  1630.   /* Isolate opcode */
  1631.   if (*(iP) == ' ')
  1632.     {
  1633.       iP++;
  1634.     }                /* Skip lead space, if any */
  1635.   args[0] = iP;
  1636.   for (; *iP != ' '; iP++)
  1637.     {
  1638.       if (*iP == '\0')
  1639.     {
  1640.       /* There are no operands */
  1641.       if (args[0] == iP)
  1642.         {
  1643.           /* We never moved: there was no opcode either! */
  1644.           as_bad ("missing opcode");
  1645.           return -1;
  1646.         }
  1647.       return 0;
  1648.     }
  1649.     }
  1650.   *iP++ = '\0';            /* Terminate opcode */
  1651.   return (get_args (iP, args));
  1652. }                /* i_scan() */
  1653.  
  1654.  
  1655. /*****************************************************************************
  1656.    mem_fmt:    generate a MEMA- or MEMB-format instruction
  1657.  
  1658.   *************************************************************************** */
  1659. static void
  1660. mem_fmt (args, oP, callx)
  1661.      char *args[];        /* args[0]->opcode mnemonic, args[1-3]->operands */
  1662.      struct i960_opcode *oP;    /* Pointer to description of instruction */
  1663.      int callx;            /* Is this a callx opcode */
  1664. {
  1665.   int i;            /* Loop counter */
  1666.   struct regop regop;        /* Description of register operand */
  1667.   char opdesc;            /* Operand descriptor byte */
  1668.   memS instr;            /* Description of binary to be output */
  1669.   char *outP;            /* Where the binary was output to */
  1670.   expressionS expr;        /* Parsed expression */
  1671.   /* ->description of deferred address fixup */
  1672.   fixS *fixP;
  1673.  
  1674. #ifdef OBJ_COFF
  1675.   /* COFF support isn't in place yet for callx relaxing.  */
  1676.   callx = 0;
  1677. #endif
  1678.  
  1679.   memset (&instr, '\0', sizeof (memS));
  1680.   instr.opcode = oP->opcode;
  1681.  
  1682.   /* Process operands. */
  1683.   for (i = 1; i <= oP->num_ops; i++)
  1684.     {
  1685.       opdesc = oP->operand[i - 1];
  1686.  
  1687.       if (MEMOP (opdesc))
  1688.     {
  1689.       parse_memop (&instr, args[i], oP->format);
  1690.     }
  1691.       else
  1692.     {
  1693.       parse_regop (®op, args[i], opdesc);
  1694.       instr.opcode |= regop.n << 19;
  1695.     }
  1696.     }
  1697.  
  1698.   /* Output opcode */
  1699.   outP = emit (instr.opcode);
  1700.  
  1701.   if (instr.disp == 0)
  1702.     {
  1703.       return;
  1704.     }
  1705.  
  1706.   /* Parse and process the displacement */
  1707.   parse_expr (instr.e, &expr);
  1708.   switch (expr.X_op)
  1709.     {
  1710.     case O_illegal:
  1711.       as_bad ("expression syntax error");
  1712.       break;
  1713.  
  1714.     case O_constant:
  1715.       if (instr.disp == 32)
  1716.     {
  1717.       (void) emit (offs (expr));    /* Output displacement */
  1718.     }
  1719.       else
  1720.     {
  1721.       /* 12-bit displacement */
  1722.       if (offs (expr) & ~0xfff)
  1723.         {
  1724.           /* Won't fit in 12 bits: convert already-output
  1725.            * instruction to MEMB format, output
  1726.            * displacement.
  1727.            */
  1728.           mema_to_memb (outP);
  1729.           (void) emit (offs (expr));
  1730.         }
  1731.       else
  1732.         {
  1733.           /* WILL fit in 12 bits:  OR into opcode and
  1734.            * overwrite the binary we already put out
  1735.            */
  1736.           instr.opcode |= offs (expr);
  1737.           md_number_to_chars (outP, instr.opcode, 4);
  1738.         }
  1739.     }
  1740.       break;
  1741.  
  1742.     default:
  1743.       if (instr.disp == 12)
  1744.     {
  1745.       /* Displacement is dependent on a symbol, whose value
  1746.        * may change at link time.  We HAVE to reserve 32 bits.
  1747.        * Convert already-output opcode to MEMB format.
  1748.        */
  1749.       mema_to_memb (outP);
  1750.     }
  1751.  
  1752.       /* Output 0 displacement and set up address fixup for when
  1753.        * this symbol's value becomes known.
  1754.        */
  1755.       outP = emit ((long) 0);
  1756.       fixP = fix_new_exp (frag_now,
  1757.               outP - frag_now->fr_literal,
  1758.               4,
  1759.               &expr,
  1760.               0,
  1761.               NO_RELOC);
  1762.       /* Steve's linker relaxing hack.  Mark this 32-bit relocation as
  1763.          being in the instruction stream, specifically as part of a callx
  1764.          instruction.  */
  1765.       fixP->fx_bsr = callx;
  1766.       break;
  1767.     }
  1768. }                /* memfmt() */
  1769.  
  1770.  
  1771. /*****************************************************************************
  1772.    mema_to_memb:    convert a MEMA-format opcode to a MEMB-format opcode.
  1773.  
  1774.    There are 2 possible MEMA formats:
  1775.       - displacement only
  1776.       - displacement + abase
  1777.  
  1778.    They are distinguished by the setting of the MEMA_ABASE bit.
  1779.  
  1780.   *************************************************************************** */
  1781. static void
  1782. mema_to_memb (opcodeP)
  1783.      char *opcodeP;        /* Where to find the opcode, in target byte order */
  1784. {
  1785.   long opcode;            /* Opcode in host byte order */
  1786.   long mode;            /* Mode bits for MEMB instruction */
  1787.  
  1788.   opcode = md_chars_to_number (opcodeP, 4);
  1789.   know (!(opcode & MEMB_BIT));
  1790.  
  1791.   mode = MEMB_BIT | D_BIT;
  1792.   if (opcode & MEMA_ABASE)
  1793.     {
  1794.       mode |= A_BIT;
  1795.     }
  1796.  
  1797.   opcode &= 0xffffc000;        /* Clear MEMA offset and mode bits */
  1798.   opcode |= mode;        /* Set MEMB mode bits */
  1799.  
  1800.   md_number_to_chars (opcodeP, opcode, 4);
  1801. }                /* mema_to_memb() */
  1802.  
  1803.  
  1804. /*****************************************************************************
  1805.    parse_expr:        parse an expression
  1806.  
  1807.       Use base assembler's expression parser to parse an expression.
  1808.       It, unfortunately, runs off a global which we have to save/restore
  1809.       in order to make it work for us.
  1810.  
  1811.       An empty expression string is treated as an absolute 0.
  1812.  
  1813.       Sets O_illegal regardless of expression evaluation if entire input
  1814.       string is not consumed in the evaluation -- tolerate no dangling junk!
  1815.  
  1816.   *************************************************************************** */
  1817. static void
  1818. parse_expr (textP, expP)
  1819.      char *textP;        /* Text of expression to be parsed */
  1820.      expressionS *expP;        /* Where to put the results of parsing */
  1821. {
  1822.   char *save_in;        /* Save global here */
  1823.   symbolS *symP;
  1824.  
  1825.   know (textP);
  1826.  
  1827.   if (*textP == '\0')
  1828.     {
  1829.       /* Treat empty string as absolute 0 */
  1830.       expP->X_add_symbol = expP->X_op_symbol = NULL;
  1831.       expP->X_add_number = 0;
  1832.       expP->X_op = O_constant;
  1833.     }
  1834.   else
  1835.     {
  1836.       save_in = input_line_pointer;    /* Save global */
  1837.       input_line_pointer = textP;    /* Make parser work for us */
  1838.  
  1839.       (void) expression (expP);
  1840.       if (input_line_pointer - textP != strlen (textP))
  1841.     {
  1842.       /* Did not consume all of the input */
  1843.       expP->X_op = O_illegal;
  1844.     }
  1845.       symP = expP->X_add_symbol;
  1846.       if (symP && (hash_find (reg_hash, S_GET_NAME (symP))))
  1847.     {
  1848.       /* Register name in an expression */
  1849.       /* FIXME: this isn't much of a check any more.  */
  1850.       expP->X_op = O_illegal;
  1851.     }
  1852.  
  1853.       input_line_pointer = save_in;    /* Restore global */
  1854.     }
  1855. }
  1856.  
  1857.  
  1858. /*****************************************************************************
  1859.    parse_ldcont:
  1860.       Parse and replace a 'ldconst' pseudo-instruction with an appropriate
  1861.       i80960 instruction.
  1862.  
  1863.       Assumes the input consists of:
  1864.           arg[0]    opcode mnemonic ('ldconst')
  1865.           arg[1]  first operand (constant)
  1866.           arg[2]    name of register to be loaded
  1867.  
  1868.       Replaces opcode and/or operands as appropriate.
  1869.  
  1870.       Returns the new number of arguments, or -1 on failure.
  1871.  
  1872.   *************************************************************************** */
  1873. static
  1874. int
  1875. parse_ldconst (arg)
  1876.      char *arg[];        /* See above */
  1877. {
  1878.   int n;            /* Constant to be loaded */
  1879.   int shift;            /* Shift count for "shlo" instruction */
  1880.   static char buf[5];        /* Literal for first operand */
  1881.   static char buf2[5];        /* Literal for second operand */
  1882.   expressionS e;        /* Parsed expression */
  1883.  
  1884.  
  1885.   arg[3] = NULL;        /* So we can tell at the end if it got used or not */
  1886.  
  1887.   parse_expr (arg[1], &e);
  1888.   switch (e.X_op)
  1889.     {
  1890.     default:
  1891.       /* We're dependent on one or more symbols -- use "lda" */
  1892.       arg[0] = "lda";
  1893.       break;
  1894.  
  1895.     case O_constant:
  1896.       /* Try the following mappings:
  1897.        *      ldconst 0,<reg>  ->mov  0,<reg>
  1898.        *        ldconst 31,<reg> ->mov  31,<reg>
  1899.        *        ldconst 32,<reg> ->addo 1,31,<reg>
  1900.        *        ldconst 62,<reg> ->addo 31,31,<reg>
  1901.        *        ldconst 64,<reg> ->shlo 8,3,<reg>
  1902.        *        ldconst -1,<reg> ->subo 1,0,<reg>
  1903.        *        ldconst -31,<reg>->subo 31,0,<reg>
  1904.        *
  1905.        * anthing else becomes:
  1906.        *        lda xxx,<reg>
  1907.        */
  1908.       n = offs (e);
  1909.       if ((0 <= n) && (n <= 31))
  1910.     {
  1911.       arg[0] = "mov";
  1912.  
  1913.     }
  1914.       else if ((-31 <= n) && (n <= -1))
  1915.     {
  1916.       arg[0] = "subo";
  1917.       arg[3] = arg[2];
  1918.       sprintf (buf, "%d", -n);
  1919.       arg[1] = buf;
  1920.       arg[2] = "0";
  1921.  
  1922.     }
  1923.       else if ((32 <= n) && (n <= 62))
  1924.     {
  1925.       arg[0] = "addo";
  1926.       arg[3] = arg[2];
  1927.       arg[1] = "31";
  1928.       sprintf (buf, "%d", n - 31);
  1929.       arg[2] = buf;
  1930.  
  1931.     }
  1932.       else if ((shift = shift_ok (n)) != 0)
  1933.     {
  1934.       arg[0] = "shlo";
  1935.       arg[3] = arg[2];
  1936.       sprintf (buf, "%d", shift);
  1937.       arg[1] = buf;
  1938.       sprintf (buf2, "%d", n >> shift);
  1939.       arg[2] = buf2;
  1940.  
  1941.     }
  1942.       else
  1943.     {
  1944.       arg[0] = "lda";
  1945.     }
  1946.       break;
  1947.  
  1948.     case O_illegal:
  1949.       as_bad ("invalid constant");
  1950.       return -1;
  1951.       break;
  1952.     }
  1953.   return (arg[3] == 0) ? 2 : 3;
  1954. }
  1955.  
  1956. /*****************************************************************************
  1957.    parse_memop:    parse a memory operand
  1958.  
  1959.       This routine is based on the observation that the 4 mode bits of the
  1960.       MEMB format, taken individually, have fairly consistent meaning:
  1961.  
  1962.            M3 (bit 13): 1 if displacement is present (D_BIT)
  1963.            M2 (bit 12): 1 for MEMB instructions (MEMB_BIT)
  1964.            M1 (bit 11): 1 if index is present (I_BIT)
  1965.            M0 (bit 10): 1 if abase is present (A_BIT)
  1966.  
  1967.       So we parse the memory operand and set bits in the mode as we find
  1968.       things.  Then at the end, if we go to MEMB format, we need only set
  1969.       the MEMB bit (M2) and our mode is built for us.
  1970.  
  1971.       Unfortunately, I said "fairly consistent".  The exceptions:
  1972.  
  1973.            DBIA
  1974.            0100    Would seem illegal, but means "abase-only".
  1975.  
  1976.            0101    Would seem to mean "abase-only" -- it means IP-relative.
  1977.               Must be converted to 0100.
  1978.  
  1979.            0110    Would seem to mean "index-only", but is reserved.
  1980.               We turn on the D bit and provide a 0 displacement.
  1981.  
  1982.       The other thing to observe is that we parse from the right, peeling
  1983.       things * off as we go:  first any index spec, then any abase, then
  1984.       the displacement.
  1985.  
  1986.   *************************************************************************** */
  1987. static
  1988. void
  1989. parse_memop (memP, argP, optype)
  1990.      memS *memP;        /* Where to put the results */
  1991.      char *argP;        /* Text of the operand to be parsed */
  1992.      int optype;        /* MEM1, MEM2, MEM4, MEM8, MEM12, or MEM16 */
  1993. {
  1994.   char *indexP;            /* Pointer to index specification with "[]" removed */
  1995.   char *p;            /* Temp char pointer */
  1996.   char iprel_flag;        /* True if this is an IP-relative operand */
  1997.   int regnum;            /* Register number */
  1998.   /* Scale factor: 1,2,4,8, or 16.  Later converted to internal format
  1999.      (0,1,2,3,4 respectively).  */
  2000.   int scale;
  2001.   int mode;            /* MEMB mode bits */
  2002.   int *intP;            /* Pointer to register number */
  2003.  
  2004.   /* The following table contains the default scale factors for each
  2005.      type of memory instruction.  It is accessed using (optype-MEM1)
  2006.      as an index -- thus it assumes the 'optype' constants are
  2007.      assigned consecutive values, in the order they appear in this
  2008.      table.  */
  2009.   static const int def_scale[] =
  2010.   {
  2011.     1,                /* MEM1 */
  2012.     2,                /* MEM2 */
  2013.     4,                /* MEM4 */
  2014.     8,                /* MEM8 */
  2015.     -1,                /* MEM12 -- no valid default */
  2016.     16                /* MEM16 */
  2017.   };
  2018.  
  2019.  
  2020.   iprel_flag = mode = 0;
  2021.  
  2022.   /* Any index present? */
  2023.   indexP = get_ispec (argP);
  2024.   if (indexP)
  2025.     {
  2026.       p = strchr (indexP, '*');
  2027.       if (p == NULL)
  2028.     {
  2029.       /* No explicit scale -- use default for this instruction
  2030.          type and assembler mode.  */
  2031.       if (flag_mri)
  2032.         scale = 1;
  2033.       else
  2034.         /* GNU960 compatibility */
  2035.         scale = def_scale[optype - MEM1];
  2036.     }
  2037.       else
  2038.     {
  2039.       *p++ = '\0';        /* Eliminate '*' */
  2040.  
  2041.       /* Now indexP->a '\0'-terminated register name,
  2042.          * and p->a scale factor.
  2043.        */
  2044.  
  2045.       if (!strcmp (p, "16"))
  2046.         {
  2047.           scale = 16;
  2048.         }
  2049.       else if (strchr ("1248", *p) && (p[1] == '\0'))
  2050.         {
  2051.           scale = *p - '0';
  2052.         }
  2053.       else
  2054.         {
  2055.           scale = -1;
  2056.         }
  2057.     }
  2058.  
  2059.       regnum = get_regnum (indexP);    /* Get index reg. # */
  2060.       if (!IS_RG_REG (regnum))
  2061.     {
  2062.       as_bad ("invalid index register");
  2063.       return;
  2064.     }
  2065.  
  2066.       /* Convert scale to its binary encoding */
  2067.       switch (scale)
  2068.     {
  2069.     case 1:
  2070.       scale = 0 << 7;
  2071.       break;
  2072.     case 2:
  2073.       scale = 1 << 7;
  2074.       break;
  2075.     case 4:
  2076.       scale = 2 << 7;
  2077.       break;
  2078.     case 8:
  2079.       scale = 3 << 7;
  2080.       break;
  2081.     case 16:
  2082.       scale = 4 << 7;
  2083.       break;
  2084.     default:
  2085.       as_bad ("invalid scale factor");
  2086.       return;
  2087.     };
  2088.  
  2089.       memP->opcode |= scale | regnum;    /* Set index bits in opcode */
  2090.       mode |= I_BIT;        /* Found a valid index spec */
  2091.     }
  2092.  
  2093.   /* Any abase (Register Indirect) specification present? */
  2094.   if ((p = strrchr (argP, '(')) != NULL)
  2095.     {
  2096.       /* "(" is there -- does it start a legal abase spec?  If not, it
  2097.          could be part of a displacement expression.  */
  2098.       intP = (int *) hash_find (areg_hash, p);
  2099.       if (intP != NULL)
  2100.     {
  2101.       /* Got an abase here */
  2102.       regnum = *intP;
  2103.       *p = '\0';        /* discard register spec */
  2104.       if (regnum == IPREL)
  2105.         {
  2106.           /* We have to specialcase ip-rel mode */
  2107.           iprel_flag = 1;
  2108.         }
  2109.       else
  2110.         {
  2111.           memP->opcode |= regnum << 14;
  2112.           mode |= A_BIT;
  2113.         }
  2114.     }
  2115.     }
  2116.  
  2117.   /* Any expression present? */
  2118.   memP->e = argP;
  2119.   if (*argP != '\0')
  2120.     {
  2121.       mode |= D_BIT;
  2122.     }
  2123.  
  2124.   /* Special-case ip-relative addressing */
  2125.   if (iprel_flag)
  2126.     {
  2127.       if (mode & I_BIT)
  2128.     {
  2129.       syntax ();
  2130.     }
  2131.       else
  2132.     {
  2133.       memP->opcode |= 5 << 10;    /* IP-relative mode */
  2134.       memP->disp = 32;
  2135.     }
  2136.       return;
  2137.     }
  2138.  
  2139.   /* Handle all other modes */
  2140.   switch (mode)
  2141.     {
  2142.     case D_BIT | A_BIT:
  2143.       /* Go with MEMA instruction format for now (grow to MEMB later
  2144.          if 12 bits is not enough for the displacement).  MEMA format
  2145.          has a single mode bit: set it to indicate that abase is
  2146.          present.  */
  2147.       memP->opcode |= MEMA_ABASE;
  2148.       memP->disp = 12;
  2149.       break;
  2150.  
  2151.     case D_BIT:
  2152.       /* Go with MEMA instruction format for now (grow to MEMB later
  2153.          if 12 bits is not enough for the displacement).  */
  2154.       memP->disp = 12;
  2155.       break;
  2156.  
  2157.     case A_BIT:
  2158.       /* For some reason, the bit string for this mode is not
  2159.          consistent: it should be 0 (exclusive of the MEMB bit), so we
  2160.          set it "by hand" here.  */
  2161.       memP->opcode |= MEMB_BIT;
  2162.       break;
  2163.  
  2164.     case A_BIT | I_BIT:
  2165.       /* set MEMB bit in mode, and OR in mode bits */
  2166.       memP->opcode |= mode | MEMB_BIT;
  2167.       break;
  2168.  
  2169.     case I_BIT:
  2170.       /* Treat missing displacement as displacement of 0.  */
  2171.       mode |= D_BIT;
  2172.       /* Fall into next case.  */
  2173.     case D_BIT | A_BIT | I_BIT:
  2174.     case D_BIT | I_BIT:
  2175.       /* set MEMB bit in mode, and OR in mode bits */
  2176.       memP->opcode |= mode | MEMB_BIT;
  2177.       memP->disp = 32;
  2178.       break;
  2179.  
  2180.     default:
  2181.       syntax ();
  2182.       break;
  2183.     }
  2184. }
  2185.  
  2186. /*****************************************************************************
  2187.    parse_po:    parse machine-dependent pseudo-op
  2188.  
  2189.       This is a top-level routine for machine-dependent pseudo-ops.  It slurps
  2190.       up the rest of the input line, breaks out the individual arguments,
  2191.       and dispatches them to the correct handler.
  2192.   *************************************************************************** */
  2193. static
  2194. void
  2195. parse_po (po_num)
  2196.      int po_num;        /* Pseudo-op number:  currently S_LEAFPROC or S_SYSPROC */
  2197. {
  2198.   /* Pointers operands, with no embedded whitespace.
  2199.      arg[0] unused, arg[1-3]->operands */
  2200.   char *args[4];
  2201.   int n_ops;            /* Number of operands */
  2202.   char *p;            /* Pointer to beginning of unparsed argument string */
  2203.   char eol;            /* Character that indicated end of line */
  2204.  
  2205.   extern char is_end_of_line[];
  2206.  
  2207.   /* Advance input pointer to end of line. */
  2208.   p = input_line_pointer;
  2209.   while (!is_end_of_line[(unsigned char) *input_line_pointer])
  2210.     {
  2211.       input_line_pointer++;
  2212.     }
  2213.   eol = *input_line_pointer;    /* Save end-of-line char */
  2214.   *input_line_pointer = '\0';    /* Terminate argument list */
  2215.  
  2216.   /* Parse out operands */
  2217.   n_ops = get_args (p, args);
  2218.   if (n_ops == -1)
  2219.     {
  2220.       return;
  2221.     }
  2222.  
  2223.   /* Dispatch to correct handler */
  2224.   switch (po_num)
  2225.     {
  2226.     case S_SYSPROC:
  2227.       s_sysproc (n_ops, args);
  2228.       break;
  2229.     case S_LEAFPROC:
  2230.       s_leafproc (n_ops, args);
  2231.       break;
  2232.     default:
  2233.       BAD_CASE (po_num);
  2234.       break;
  2235.     }
  2236.  
  2237.   /* Restore eol, so line numbers get updated correctly.  Base
  2238.      assembler assumes we leave input pointer pointing at char
  2239.      following the eol.  */
  2240.   *input_line_pointer++ = eol;
  2241. }
  2242.  
  2243. /*****************************************************************************
  2244.    parse_regop: parse a register operand.
  2245.  
  2246.       In case of illegal operand, issue a message and return some valid
  2247.       information so instruction processing can continue.
  2248.   *************************************************************************** */
  2249. static
  2250. void
  2251. parse_regop (regopP, optext, opdesc)
  2252.      struct regop *regopP;    /* Where to put description of register operand */
  2253.      char *optext;        /* Text of operand */
  2254.      char opdesc;        /* Descriptor byte:  what's legal for this operand */
  2255. {
  2256.   int n;            /* Register number */
  2257.   expressionS e;        /* Parsed expression */
  2258.  
  2259.   /* See if operand is a register */
  2260.   n = get_regnum (optext);
  2261.   if (n >= 0)
  2262.     {
  2263.       if (IS_RG_REG (n))
  2264.     {
  2265.       /* global or local register */
  2266.       if (!REG_ALIGN (opdesc, n))
  2267.         {
  2268.           as_bad ("unaligned register");
  2269.         }
  2270.       regopP->n = n;
  2271.       regopP->mode = 0;
  2272.       regopP->special = 0;
  2273.       return;
  2274.     }
  2275.       else if (IS_FP_REG (n) && FP_OK (opdesc))
  2276.     {
  2277.       /* Floating point register, and it's allowed */
  2278.       regopP->n = n - FP0;
  2279.       regopP->mode = 1;
  2280.       regopP->special = 0;
  2281.       return;
  2282.     }
  2283.       else if (IS_SF_REG (n) && SFR_OK (opdesc))
  2284.     {
  2285.       /* Special-function register, and it's allowed */
  2286.       regopP->n = n - SF0;
  2287.       regopP->mode = 0;
  2288.       regopP->special = 1;
  2289.       if (!targ_has_sfr (regopP->n))
  2290.         {
  2291.           as_bad ("no such sfr in this architecture");
  2292.         }
  2293.       return;
  2294.     }
  2295.     }
  2296.   else if (LIT_OK (opdesc))
  2297.     {
  2298.       /* How about a literal?  */
  2299.       regopP->mode = 1;
  2300.       regopP->special = 0;
  2301.       if (FP_OK (opdesc))
  2302.     {            /* floating point literal acceptable */
  2303.       /* Skip over 0f, 0d, or 0e prefix */
  2304.       if ((optext[0] == '0')
  2305.           && (optext[1] >= 'd')
  2306.           && (optext[1] <= 'f'))
  2307.         {
  2308.           optext += 2;
  2309.         }
  2310.  
  2311.       if (!strcmp (optext, "0.0") || !strcmp (optext, "0"))
  2312.         {
  2313.           regopP->n = 0x10;
  2314.           return;
  2315.         }
  2316.       if (!strcmp (optext, "1.0") || !strcmp (optext, "1"))
  2317.         {
  2318.           regopP->n = 0x16;
  2319.           return;
  2320.         }
  2321.  
  2322.     }
  2323.       else
  2324.     {            /* fixed point literal acceptable */
  2325.       parse_expr (optext, &e);
  2326.       if (e.X_op != O_constant
  2327.           || (offs (e) < 0) || (offs (e) > 31))
  2328.         {
  2329.           as_bad ("illegal literal");
  2330.           offs (e) = 0;
  2331.         }
  2332.       regopP->n = offs (e);
  2333.       return;
  2334.     }
  2335.     }
  2336.  
  2337.   /* Nothing worked */
  2338.   syntax ();
  2339.   regopP->mode = 0;        /* Register r0 is always a good one */
  2340.   regopP->n = 0;
  2341.   regopP->special = 0;
  2342. }                /* parse_regop() */
  2343.  
  2344. /*****************************************************************************
  2345.    reg_fmt:    generate a REG-format instruction
  2346.  
  2347.   *************************************************************************** */
  2348. static void
  2349. reg_fmt (args, oP)
  2350.      char *args[];        /* args[0]->opcode mnemonic, args[1-3]->operands */
  2351.      struct i960_opcode *oP;    /* Pointer to description of instruction */
  2352. {
  2353.   long instr;            /* Binary to be output */
  2354.   struct regop regop;        /* Description of register operand */
  2355.   int n_ops;            /* Number of operands */
  2356.  
  2357.  
  2358.   instr = oP->opcode;
  2359.   n_ops = oP->num_ops;
  2360.  
  2361.   if (n_ops >= 1)
  2362.     {
  2363.       parse_regop (®op, args[1], oP->operand[0]);
  2364.  
  2365.       if ((n_ops == 1) && !(instr & M3))
  2366.     {
  2367.       /* 1-operand instruction in which the dst field should
  2368.          * be used (instead of src1).
  2369.        */
  2370.       regop.n <<= 19;
  2371.       if (regop.special)
  2372.         {
  2373.           regop.mode = regop.special;
  2374.         }
  2375.       regop.mode <<= 13;
  2376.       regop.special = 0;
  2377.     }
  2378.       else
  2379.     {
  2380.       /* regop.n goes in bit 0, needs no shifting */
  2381.       regop.mode <<= 11;
  2382.       regop.special <<= 5;
  2383.     }
  2384.       instr |= regop.n | regop.mode | regop.special;
  2385.     }
  2386.  
  2387.   if (n_ops >= 2)
  2388.     {
  2389.       parse_regop (®op, args[2], oP->operand[1]);
  2390.  
  2391.       if ((n_ops == 2) && !(instr & M3))
  2392.     {
  2393.       /* 2-operand instruction in which the dst field should
  2394.          * be used instead of src2).
  2395.        */
  2396.       regop.n <<= 19;
  2397.       if (regop.special)
  2398.         {
  2399.           regop.mode = regop.special;
  2400.         }
  2401.       regop.mode <<= 13;
  2402.       regop.special = 0;
  2403.     }
  2404.       else
  2405.     {
  2406.       regop.n <<= 14;
  2407.       regop.mode <<= 12;
  2408.       regop.special <<= 6;
  2409.     }
  2410.       instr |= regop.n | regop.mode | regop.special;
  2411.     }
  2412.   if (n_ops == 3)
  2413.     {
  2414.       parse_regop (®op, args[3], oP->operand[2]);
  2415.       if (regop.special)
  2416.     {
  2417.       regop.mode = regop.special;
  2418.     }
  2419.       instr |= (regop.n <<= 19) | (regop.mode <<= 13);
  2420.     }
  2421.   emit (instr);
  2422. }
  2423.  
  2424.  
  2425. /*****************************************************************************
  2426.    relax_cobr:
  2427.       Replace cobr instruction in a code fragment with equivalent branch and
  2428.       compare instructions, so it can reach beyond a 13-bit displacement.
  2429.       Set up an address fix/relocation for the new branch instruction.
  2430.  
  2431.   *************************************************************************** */
  2432.  
  2433. /* This "conditional jump" table maps cobr instructions into
  2434.    equivalent compare and branch opcodes.  */
  2435. static const
  2436. struct
  2437. {
  2438.   long compare;
  2439.   long branch;
  2440. }
  2441.  
  2442. coj[] =
  2443. {                /* COBR OPCODE: */
  2444.   { CHKBIT, BNO },        /*      0x30 - bbc */
  2445.   { CMPO, BG },            /*      0x31 - cmpobg */
  2446.   { CMPO, BE },            /*      0x32 - cmpobe */
  2447.   { CMPO, BGE },        /*      0x33 - cmpobge */
  2448.   { CMPO, BL },            /*      0x34 - cmpobl */
  2449.   { CMPO, BNE },        /*      0x35 - cmpobne */
  2450.   { CMPO, BLE },        /*      0x36 - cmpoble */
  2451.   { CHKBIT, BO },        /*      0x37 - bbs */
  2452.   { CMPI, BNO },        /*      0x38 - cmpibno */
  2453.   { CMPI, BG },            /*      0x39 - cmpibg */
  2454.   { CMPI, BE },            /*      0x3a - cmpibe */
  2455.   { CMPI, BGE },        /*      0x3b - cmpibge */
  2456.   { CMPI, BL },            /*      0x3c - cmpibl */
  2457.   { CMPI, BNE },        /*      0x3d - cmpibne */
  2458.   { CMPI, BLE },        /*      0x3e - cmpible */
  2459.   { CMPI, BO },            /*      0x3f - cmpibo */
  2460. };
  2461.  
  2462. static
  2463. void
  2464. relax_cobr (fragP)
  2465.      register fragS *fragP;    /* fragP->fr_opcode is assumed to point to
  2466.                  * the cobr instruction, which comes at the
  2467.                  * end of the code fragment.
  2468.                  */
  2469. {
  2470.   int opcode, src1, src2, m1, s2;
  2471.   /* Bit fields from cobr instruction */
  2472.   long bp_bits;            /* Branch prediction bits from cobr instruction */
  2473.   long instr;            /* A single i960 instruction */
  2474.   /* ->instruction to be replaced */
  2475.   char *iP;
  2476.   fixS *fixP;            /* Relocation that can be done at assembly time */
  2477.  
  2478.   /* PICK UP & PARSE COBR INSTRUCTION */
  2479.   iP = fragP->fr_opcode;
  2480.   instr = md_chars_to_number (iP, 4);
  2481.   opcode = ((instr >> 24) & 0xff) - 0x30;    /* "-0x30" for table index */
  2482.   src1 = (instr >> 19) & 0x1f;
  2483.   m1 = (instr >> 13) & 1;
  2484.   s2 = instr & 1;
  2485.   src2 = (instr >> 14) & 0x1f;
  2486.   bp_bits = instr & BP_MASK;
  2487.  
  2488.   /* GENERATE AND OUTPUT COMPARE INSTRUCTION */
  2489.   instr = coj[opcode].compare
  2490.     | src1 | (m1 << 11) | (s2 << 6) | (src2 << 14);
  2491.   md_number_to_chars (iP, instr, 4);
  2492.  
  2493.   /* OUTPUT BRANCH INSTRUCTION */
  2494.   md_number_to_chars (iP + 4, coj[opcode].branch | bp_bits, 4);
  2495.  
  2496.   /* SET UP ADDRESS FIXUP/RELOCATION */
  2497.   fixP = fix_new (fragP,
  2498.           iP + 4 - fragP->fr_literal,
  2499.           4,
  2500.           fragP->fr_symbol,
  2501.           fragP->fr_offset,
  2502.           1,
  2503.           NO_RELOC);
  2504.  
  2505.   fixP->fx_bit_fixP = (bit_fixS *) 24;    /* Store size of bit field */
  2506.  
  2507.   fragP->fr_fix += 4;
  2508.   frag_wane (fragP);
  2509. }
  2510.  
  2511.  
  2512. /*****************************************************************************
  2513.    reloc_callj:    Relocate a 'callj' instruction
  2514.  
  2515.       This is a "non-(GNU)-standard" machine-dependent hook.  The base
  2516.       assembler calls it when it decides it can relocate an address at
  2517.       assembly time instead of emitting a relocation directive.
  2518.  
  2519.       Check to see if the relocation involves a 'callj' instruction to a:
  2520.           sysproc:    Replace the default 'call' instruction with a 'calls'
  2521.           leafproc:    Replace the default 'call' instruction with a 'bal'.
  2522.           other proc:    Do nothing.
  2523.  
  2524.       See b.out.h for details on the 'n_other' field in a symbol structure.
  2525.  
  2526.    IMPORTANT!:
  2527.       Assumes the caller has already figured out, in the case of a leafproc,
  2528.       to use the 'bal' entry point, and has substituted that symbol into the
  2529.       passed fixup structure.
  2530.  
  2531.   *************************************************************************** */
  2532. void
  2533. reloc_callj (fixP)
  2534.      /* Relocation that can be done at assembly time */
  2535.      fixS *fixP;
  2536. {
  2537.   /* Points to the binary for the instruction being relocated.  */
  2538.   char *where;
  2539.  
  2540.   if (!fixP->fx_tcbit)
  2541.     {
  2542.       /* This wasn't a callj instruction in the first place */
  2543.       return;
  2544.     }
  2545.  
  2546.   where = fixP->fx_frag->fr_literal + fixP->fx_where;
  2547.  
  2548.   if (TC_S_IS_SYSPROC (fixP->fx_addsy))
  2549.     {
  2550.       /* Symbol is a .sysproc: replace 'call' with 'calls'.  System
  2551.          procedure number is (other-1).  */
  2552.       md_number_to_chars (where, CALLS | TC_S_GET_SYSPROC (fixP->fx_addsy), 4);
  2553.  
  2554.       /* Nothing else needs to be done for this instruction.  Make
  2555.          sure 'md_number_to_field()' will perform a no-op.  */
  2556.       fixP->fx_bit_fixP = (bit_fixS *) 1;
  2557.  
  2558.     }
  2559.   else if (TC_S_IS_CALLNAME (fixP->fx_addsy))
  2560.     {
  2561.       /* Should not happen: see block comment above */
  2562.       as_fatal ("Trying to 'bal' to %s", S_GET_NAME (fixP->fx_addsy));
  2563.     }
  2564.   else if (TC_S_IS_BALNAME (fixP->fx_addsy))
  2565.     {
  2566.       /* Replace 'call' with 'bal'; both instructions have the same
  2567.          format, so calling code should complete relocation as if
  2568.          nothing happened here.  */
  2569.       md_number_to_chars (where, BAL, 4);
  2570.     }
  2571.   else if (TC_S_IS_BADPROC (fixP->fx_addsy))
  2572.     {
  2573.       as_bad ("Looks like a proc, but can't tell what kind.\n");
  2574.     }                /* switch on proc type */
  2575.  
  2576.   /* else Symbol is neither a sysproc nor a leafproc */
  2577. }
  2578.  
  2579.  
  2580. /*****************************************************************************
  2581.    s_leafproc:    process .leafproc pseudo-op
  2582.  
  2583.       .leafproc takes two arguments, the second one is optional:
  2584.           arg[1]: name of 'call' entry point to leaf procedure
  2585.           arg[2]: name of 'bal' entry point to leaf procedure
  2586.  
  2587.       If the two arguments are identical, or if the second one is missing,
  2588.       the first argument is taken to be the 'bal' entry point.
  2589.  
  2590.       If there are 2 distinct arguments, we must make sure that the 'bal'
  2591.       entry point immediately follows the 'call' entry point in the linked
  2592.       list of symbols.
  2593.  
  2594.   *************************************************************************** */
  2595. static void
  2596. s_leafproc (n_ops, args)
  2597.      int n_ops;            /* Number of operands */
  2598.      char *args[];        /* args[1]->1st operand, args[2]->2nd operand */
  2599. {
  2600.   symbolS *callP;        /* Pointer to leafproc 'call' entry point symbol */
  2601.   symbolS *balP;        /* Pointer to leafproc 'bal' entry point symbol */
  2602.  
  2603.   if ((n_ops != 1) && (n_ops != 2))
  2604.     {
  2605.       as_bad ("should have 1 or 2 operands");
  2606.       return;
  2607.     }                /* Check number of arguments */
  2608.  
  2609.   /* Find or create symbol for 'call' entry point. */
  2610.   callP = symbol_find_or_make (args[1]);
  2611.  
  2612.   if (TC_S_IS_CALLNAME (callP))
  2613.     {
  2614.       as_warn ("Redefining leafproc %s", S_GET_NAME (callP));
  2615.     }                /* is leafproc */
  2616.  
  2617.   /* If that was the only argument, use it as the 'bal' entry point.
  2618.      * Otherwise, mark it as the 'call' entry point and find or create
  2619.      * another symbol for the 'bal' entry point.
  2620.    */
  2621.   if ((n_ops == 1) || !strcmp (args[1], args[2]))
  2622.     {
  2623.       TC_S_FORCE_TO_BALNAME (callP);
  2624.  
  2625.     }
  2626.   else
  2627.     {
  2628.       TC_S_FORCE_TO_CALLNAME (callP);
  2629.  
  2630.       balP = symbol_find_or_make (args[2]);
  2631.       if (TC_S_IS_CALLNAME (balP))
  2632.     {
  2633.       as_warn ("Redefining leafproc %s", S_GET_NAME (balP));
  2634.     }
  2635.       TC_S_FORCE_TO_BALNAME (balP);
  2636.  
  2637.       tc_set_bal_of_call (callP, balP);
  2638.     }                /* if only one arg, or the args are the same */
  2639. }
  2640.  
  2641.  
  2642. /*
  2643.    s_sysproc: process .sysproc pseudo-op
  2644.  
  2645.         .sysproc takes two arguments:
  2646.                 arg[1]: name of entry point to system procedure
  2647.                 arg[2]: 'entry_num' (index) of system procedure in the range
  2648.                         [0,31] inclusive.
  2649.  
  2650.         For [ab].out, we store the 'entrynum' in the 'n_other' field of
  2651.         the symbol.  Since that entry is normally 0, we bias 'entrynum'
  2652.         by adding 1 to it.  It must be unbiased before it is used.  */
  2653. static void
  2654. s_sysproc (n_ops, args)
  2655.      int n_ops;            /* Number of operands */
  2656.      char *args[];        /* args[1]->1st operand, args[2]->2nd operand */
  2657. {
  2658.   expressionS exp;
  2659.   symbolS *symP;
  2660.  
  2661.   if (n_ops != 2)
  2662.     {
  2663.       as_bad ("should have two operands");
  2664.       return;
  2665.     }                /* bad arg count */
  2666.  
  2667.   /* Parse "entry_num" argument and check it for validity. */
  2668.   parse_expr (args[2], &exp);
  2669.   if (exp.X_op != O_constant
  2670.       || (offs (exp) < 0)
  2671.       || (offs (exp) > 31))
  2672.     {
  2673.       as_bad ("'entry_num' must be absolute number in [0,31]");
  2674.       return;
  2675.     }
  2676.  
  2677.   /* Find/make symbol and stick entry number (biased by +1) into it */
  2678.   symP = symbol_find_or_make (args[1]);
  2679.  
  2680.   if (TC_S_IS_SYSPROC (symP))
  2681.     {
  2682.       as_warn ("Redefining entrynum for sysproc %s", S_GET_NAME (symP));
  2683.     }                /* redefining */
  2684.  
  2685.   TC_S_SET_SYSPROC (symP, offs (exp));    /* encode entry number */
  2686.   TC_S_FORCE_TO_SYSPROC (symP);
  2687. }
  2688.  
  2689.  
  2690. /*****************************************************************************
  2691.    shift_ok:
  2692.       Determine if a "shlo" instruction can be used to implement a "ldconst".
  2693.       This means that some number X < 32 can be shifted left to produce the
  2694.       constant of interest.
  2695.  
  2696.       Return the shift count, or 0 if we can't do it.
  2697.       Caller calculates X by shifting original constant right 'shift' places.
  2698.  
  2699.   *************************************************************************** */
  2700. static
  2701. int
  2702. shift_ok (n)
  2703.      int n;            /* The constant of interest */
  2704. {
  2705.   int shift;            /* The shift count */
  2706.  
  2707.   if (n <= 0)
  2708.     {
  2709.       /* Can't do it for negative numbers */
  2710.       return 0;
  2711.     }
  2712.  
  2713.   /* Shift 'n' right until a 1 is about to be lost */
  2714.   for (shift = 0; (n & 1) == 0; shift++)
  2715.     {
  2716.       n >>= 1;
  2717.     }
  2718.  
  2719.   if (n >= 32)
  2720.     {
  2721.       return 0;
  2722.     }
  2723.   return shift;
  2724. }
  2725.  
  2726.  
  2727. /* syntax: issue syntax error */
  2728.  
  2729. static void
  2730. syntax ()
  2731. {
  2732.   as_bad ("syntax error");
  2733. }                /* syntax() */
  2734.  
  2735.  
  2736. /* targ_has_sfr:
  2737.  
  2738.    Return TRUE iff the target architecture supports the specified
  2739.    special-function register (sfr).  */
  2740.  
  2741. static
  2742. int
  2743. targ_has_sfr (n)
  2744.      int n;            /* Number (0-31) of sfr */
  2745. {
  2746.   switch (architecture)
  2747.     {
  2748.     case ARCH_KA:
  2749.     case ARCH_KB:
  2750.     case ARCH_MC:
  2751.     case ARCH_JX:
  2752.       return 0;
  2753.     case ARCH_HX:
  2754.       return ((0 <= n) && (n <= 4));
  2755.     case ARCH_CA:
  2756.     default:
  2757.       return ((0 <= n) && (n <= 2));
  2758.     }
  2759. }
  2760.  
  2761.  
  2762. /* targ_has_iclass:
  2763.  
  2764.    Return TRUE iff the target architecture supports the indicated
  2765.    class of instructions.  */
  2766. static
  2767. int
  2768. targ_has_iclass (ic)
  2769.      /* Instruction class;  one of:
  2770.         I_BASE, I_CX, I_DEC, I_KX, I_FP, I_MIL, I_CASIM, I_CX2, I_HX, I_HX2
  2771.       */
  2772.      int ic;
  2773. {
  2774.   iclasses_seen |= ic;
  2775.   switch (architecture)
  2776.     {
  2777.     case ARCH_KA:
  2778.       return ic & (I_BASE | I_KX);
  2779.     case ARCH_KB:
  2780.       return ic & (I_BASE | I_KX | I_FP | I_DEC);
  2781.     case ARCH_MC:
  2782.       return ic & (I_BASE | I_KX | I_FP | I_DEC | I_MIL);
  2783.     case ARCH_CA:
  2784.       return ic & (I_BASE | I_CX | I_CX2 | I_CASIM);
  2785.     case ARCH_JX:
  2786.       return ic & (I_BASE | I_CX2 | I_JX);
  2787.     case ARCH_HX:
  2788.       return ic & (I_BASE | I_CX2 | I_JX | I_HX);
  2789.     default:
  2790.       if ((iclasses_seen & (I_KX | I_FP | I_DEC | I_MIL))
  2791.       && (iclasses_seen & (I_CX | I_CX2)))
  2792.     {
  2793.       as_warn ("architecture of opcode conflicts with that of earlier instruction(s)");
  2794.       iclasses_seen &= ~ic;
  2795.     }
  2796.       return 1;
  2797.     }
  2798. }
  2799.  
  2800. /* Handle the MRI .endian pseudo-op.  */
  2801.  
  2802. static void
  2803. s_endian (ignore)
  2804.      int ignore;
  2805. {
  2806.   char *name;
  2807.   char c;
  2808.  
  2809.   name = input_line_pointer;
  2810.   c = get_symbol_end ();
  2811.   if (strcasecmp (name, "little") == 0)
  2812.     ;
  2813.   else if (strcasecmp (name, "big") == 0)
  2814.     as_bad ("big endian mode is not supported");
  2815.   else
  2816.     as_warn ("ignoring unrecognized .endian type `%s'", name);
  2817.  
  2818.   *input_line_pointer = c;
  2819.  
  2820.   demand_empty_rest_of_line ();
  2821. }
  2822.  
  2823. /* We have no need to default values of symbols. */
  2824.  
  2825. /* ARGSUSED */
  2826. symbolS *
  2827. md_undefined_symbol (name)
  2828.      char *name;
  2829. {
  2830.   return 0;
  2831. }
  2832.  
  2833. /* Exactly what point is a PC-relative offset relative TO?
  2834.    On the i960, they're relative to the address of the instruction,
  2835.    which we have set up as the address of the fixup too. */
  2836. long
  2837. md_pcrel_from (fixP)
  2838.      fixS *fixP;
  2839. {
  2840.   return fixP->fx_where + fixP->fx_frag->fr_address;
  2841. }
  2842.  
  2843. void
  2844. md_apply_fix (fixP, val)
  2845.      fixS *fixP;
  2846.      long val;
  2847. {
  2848.   char *place = fixP->fx_where + fixP->fx_frag->fr_literal;
  2849.  
  2850.   if (!fixP->fx_bit_fixP)
  2851.     {
  2852.       /* For callx, we always want to write out zero, and emit a
  2853.      symbolic relocation.  */
  2854.       if (fixP->fx_bsr)
  2855.     val = 0;
  2856.  
  2857.       fixP->fx_addnumber = val;
  2858.       md_number_to_imm (place, val, fixP->fx_size, fixP);
  2859.     }
  2860.   else
  2861.     md_number_to_field (place, val, fixP->fx_bit_fixP);
  2862. }
  2863.  
  2864. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  2865. void
  2866. tc_bout_fix_to_chars (where, fixP, segment_address_in_file)
  2867.      char *where;
  2868.      fixS *fixP;
  2869.      relax_addressT segment_address_in_file;
  2870. {
  2871.   static const unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
  2872.   struct relocation_info ri;
  2873.   symbolS *symbolP;
  2874.  
  2875.   memset ((char *) &ri, '\0', sizeof (ri));
  2876.   symbolP = fixP->fx_addsy;
  2877.   know (symbolP != 0 || fixP->fx_r_type != NO_RELOC);
  2878.   ri.r_bsr = fixP->fx_bsr;    /*SAC LD RELAX HACK */
  2879.   /* These two 'cuz of NS32K */
  2880.   ri.r_callj = fixP->fx_tcbit;
  2881.   if (fixP->fx_bit_fixP)
  2882.     ri.r_length = 2;
  2883.   else
  2884.     ri.r_length = nbytes_r_length[fixP->fx_size];
  2885.   ri.r_pcrel = fixP->fx_pcrel;
  2886.   ri.r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file;
  2887.  
  2888.   if (fixP->fx_r_type != NO_RELOC)
  2889.     {
  2890.       switch (fixP->fx_r_type)
  2891.     {
  2892.     case rs_align:
  2893.       ri.r_index = -2;
  2894.       ri.r_pcrel = 1;
  2895.       ri.r_length = fixP->fx_size - 1;
  2896.       break;
  2897.     case rs_org:
  2898.       ri.r_index = -2;
  2899.       ri.r_pcrel = 0;
  2900.       break;
  2901.     case rs_fill:
  2902.       ri.r_index = -1;
  2903.       break;
  2904.     default:
  2905.       abort ();
  2906.     }
  2907.       ri.r_extern = 0;
  2908.     }
  2909.   else if (linkrelax || !S_IS_DEFINED (symbolP) || fixP->fx_bsr)
  2910.     {
  2911.       ri.r_extern = 1;
  2912.       ri.r_index = symbolP->sy_number;
  2913.     }
  2914.   else
  2915.     {
  2916.       ri.r_extern = 0;
  2917.       ri.r_index = S_GET_TYPE (symbolP);
  2918.     }
  2919.  
  2920.   /* Output the relocation information in machine-dependent form. */
  2921.   md_ri_to_chars (where, &ri);
  2922. }
  2923.  
  2924. #endif /* OBJ_AOUT or OBJ_BOUT */
  2925.  
  2926. #if defined (OBJ_COFF) && defined (BFD)
  2927. short
  2928. tc_coff_fix2rtype (fixP)
  2929.      fixS *fixP;
  2930. {
  2931.   if (fixP->fx_bsr)
  2932.     abort ();
  2933.  
  2934.   if (fixP->fx_pcrel == 0 && fixP->fx_size == 4)
  2935.     return R_RELLONG;
  2936.  
  2937.   if (fixP->fx_pcrel != 0 && fixP->fx_size == 4)
  2938.     return R_IPRMED;
  2939.  
  2940.   abort ();
  2941.   return 0;
  2942. }
  2943.  
  2944. int
  2945. tc_coff_sizemachdep (frag)
  2946.      fragS *frag;
  2947. {
  2948.   if (frag->fr_next)
  2949.     return frag->fr_next->fr_address - frag->fr_address;
  2950.   else
  2951.     return 0;
  2952. }
  2953. #endif
  2954.  
  2955. /* Align an address by rounding it up to the specified boundary.  */
  2956. valueT
  2957. md_section_align (seg, addr)
  2958.      segT seg;
  2959.      valueT addr;        /* Address to be rounded up */
  2960. {
  2961.   return ((addr + (1 << section_alignment[(int) seg]) - 1) & (-1 << section_alignment[(int) seg]));
  2962. }                /* md_section_align() */
  2963.  
  2964. extern int coff_flags;
  2965.  
  2966. #ifdef OBJ_COFF
  2967. void
  2968. tc_headers_hook (headers)
  2969.      object_headers *headers;
  2970. {
  2971.   switch (architecture)
  2972.     {
  2973.     case ARCH_KA:
  2974.       coff_flags |= F_I960KA;
  2975.       break;
  2976.  
  2977.     case ARCH_KB:
  2978.       coff_flags |= F_I960KB;
  2979.       break;
  2980.  
  2981.     case ARCH_MC:
  2982.       coff_flags |= F_I960MC;
  2983.       break;
  2984.  
  2985.     case ARCH_CA:
  2986.       coff_flags |= F_I960CA;
  2987.       break;
  2988.  
  2989.     case ARCH_JX:
  2990.       coff_flags |= F_I960JX;
  2991.       break;
  2992.  
  2993.     case ARCH_HX:
  2994.       coff_flags |= F_I960HX;
  2995.       break;
  2996.  
  2997.     default:
  2998.       if (iclasses_seen == I_BASE)
  2999.     coff_flags |= F_I960CORE;
  3000.       else if (iclasses_seen & I_CX)
  3001.     coff_flags |= F_I960CA;
  3002.       else if (iclasses_seen & I_HX)
  3003.     coff_flags |= F_I960HX;
  3004.       else if (iclasses_seen & I_JX)
  3005.     coff_flags |= F_I960JX;
  3006.       else if (iclasses_seen & I_CX2)
  3007.     coff_flags |= F_I960CA;
  3008.       else if (iclasses_seen & I_MIL)
  3009.     coff_flags |= F_I960MC;
  3010.       else if (iclasses_seen & (I_DEC | I_FP))
  3011.     coff_flags |= F_I960KB;
  3012.       else
  3013.     coff_flags |= F_I960KA;
  3014.       break;
  3015.     }
  3016.  
  3017.   if (flag_readonly_data_in_text)
  3018.     {
  3019.       headers->filehdr.f_magic = I960RWMAGIC;
  3020.       headers->aouthdr.magic = OMAGIC;
  3021.     }
  3022.   else
  3023.     {
  3024.       headers->filehdr.f_magic = I960ROMAGIC;
  3025.       headers->aouthdr.magic = NMAGIC;
  3026.     }                /* set magic numbers */
  3027. }
  3028.  
  3029. #endif /* OBJ_COFF */
  3030.  
  3031. /* Things going on here:
  3032.  
  3033.    For bout, We need to assure a couple of simplifying
  3034.    assumptions about leafprocs for the linker: the leafproc
  3035.    entry symbols will be defined in the same assembly in
  3036.    which they're declared with the '.leafproc' directive;
  3037.    and if a leafproc has both 'call' and 'bal' entry points
  3038.    they are both global or both local.
  3039.  
  3040.    For coff, the call symbol has a second aux entry that
  3041.    contains the bal entry point.  The bal symbol becomes a
  3042.    label.
  3043.  
  3044.    For coff representation, the call symbol has a second aux entry that
  3045.    contains the bal entry point.  The bal symbol becomes a label.  */
  3046.  
  3047. void
  3048. tc_crawl_symbol_chain (headers)
  3049.      object_headers *headers;
  3050. {
  3051.   symbolS *symbolP;
  3052.  
  3053.   for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
  3054.     {
  3055. #ifdef OBJ_COFF
  3056.       if (TC_S_IS_SYSPROC (symbolP))
  3057.     {
  3058.       /* second aux entry already contains the sysproc number */
  3059.       S_SET_NUMBER_AUXILIARY (symbolP, 2);
  3060.       S_SET_STORAGE_CLASS (symbolP, C_SCALL);
  3061.       S_SET_DATA_TYPE (symbolP, S_GET_DATA_TYPE (symbolP) | (DT_FCN << N_BTSHFT));
  3062.       continue;
  3063.     }            /* rewrite sysproc */
  3064. #endif /* OBJ_COFF */
  3065.  
  3066.       if (!TC_S_IS_BALNAME (symbolP) && !TC_S_IS_CALLNAME (symbolP))
  3067.     {
  3068.       continue;
  3069.     }            /* Not a leafproc symbol */
  3070.  
  3071.       if (!S_IS_DEFINED (symbolP))
  3072.     {
  3073.       as_bad ("leafproc symbol '%s' undefined", S_GET_NAME (symbolP));
  3074.     }            /* undefined leaf */
  3075.  
  3076.       if (TC_S_IS_CALLNAME (symbolP))
  3077.     {
  3078.       symbolS *balP = tc_get_bal_of_call (symbolP);
  3079.       if (S_IS_EXTERNAL (symbolP) != S_IS_EXTERNAL (balP))
  3080.         {
  3081.           S_SET_EXTERNAL (symbolP);
  3082.           S_SET_EXTERNAL (balP);
  3083.           as_warn ("Warning: making leafproc entries %s and %s both global\n",
  3084.                S_GET_NAME (symbolP), S_GET_NAME (balP));
  3085.         }            /* externality mismatch */
  3086.     }            /* if callname */
  3087.     }                /* walk the symbol chain */
  3088. }
  3089.  
  3090. /* For aout or bout, the bal immediately follows the call.
  3091.  
  3092.    For coff, we cheat and store a pointer to the bal symbol in the
  3093.    second aux entry of the call.  */
  3094.  
  3095. #undef OBJ_ABOUT
  3096. #ifdef OBJ_AOUT
  3097. #define OBJ_ABOUT
  3098. #endif
  3099. #ifdef OBJ_BOUT
  3100. #define OBJ_ABOUT
  3101. #endif
  3102.  
  3103. void
  3104. tc_set_bal_of_call (callP, balP)
  3105.      symbolS *callP;
  3106.      symbolS *balP;
  3107. {
  3108.   know (TC_S_IS_CALLNAME (callP));
  3109.   know (TC_S_IS_BALNAME (balP));
  3110.  
  3111. #ifdef OBJ_COFF
  3112.  
  3113.   callP->sy_symbol.ost_auxent[1].x_bal.x_balntry = (int) balP;
  3114.   S_SET_NUMBER_AUXILIARY (callP, 2);
  3115.  
  3116. #else /* ! OBJ_COFF */
  3117. #ifdef OBJ_ABOUT
  3118.  
  3119.   /* If the 'bal' entry doesn't immediately follow the 'call'
  3120.      * symbol, unlink it from the symbol list and re-insert it.
  3121.    */
  3122.   if (symbol_next (callP) != balP)
  3123.     {
  3124.       symbol_remove (balP, &symbol_rootP, &symbol_lastP);
  3125.       symbol_append (balP, callP, &symbol_rootP, &symbol_lastP);
  3126.     }                /* if not in order */
  3127.  
  3128. #else /* ! OBJ_ABOUT */
  3129.   (as yet unwritten.);
  3130. #endif /* ! OBJ_ABOUT */
  3131. #endif /* ! OBJ_COFF */
  3132. }
  3133.  
  3134. char *
  3135. _tc_get_bal_of_call (callP)
  3136.      symbolS *callP;
  3137. {
  3138.   symbolS *retval;
  3139.  
  3140.   know (TC_S_IS_CALLNAME (callP));
  3141.  
  3142. #ifdef OBJ_COFF
  3143.   retval = (symbolS *) (callP->sy_symbol.ost_auxent[1].x_bal.x_balntry);
  3144. #else
  3145. #ifdef OBJ_ABOUT
  3146.   retval = symbol_next (callP);
  3147. #else
  3148.   (as yet unwritten.);
  3149. #endif /* ! OBJ_ABOUT */
  3150. #endif /* ! OBJ_COFF */
  3151.  
  3152.   know (TC_S_IS_BALNAME (retval));
  3153.   return ((char *) retval);
  3154. }                /* _tc_get_bal_of_call() */
  3155.  
  3156. void
  3157. tc_coff_symbol_emit_hook (symbolP)
  3158.      symbolS *symbolP;
  3159. {
  3160.   if (TC_S_IS_CALLNAME (symbolP))
  3161.     {
  3162. #ifdef OBJ_COFF
  3163.       symbolS *balP = tc_get_bal_of_call (symbolP);
  3164.  
  3165. #if 0
  3166.       /* second aux entry contains the bal entry point */
  3167.       S_SET_NUMBER_AUXILIARY (symbolP, 2);
  3168. #endif
  3169.       symbolP->sy_symbol.ost_auxent[1].x_bal.x_balntry = S_GET_VALUE (balP);
  3170.       if (S_GET_STORAGE_CLASS (symbolP) == C_EXT)
  3171.     S_SET_STORAGE_CLASS (symbolP, C_LEAFEXT);
  3172.       else
  3173.     S_SET_STORAGE_CLASS (symbolP, C_LEAFSTAT);
  3174.       S_SET_DATA_TYPE (symbolP, S_GET_DATA_TYPE (symbolP) | (DT_FCN << N_BTSHFT));
  3175.       /* fix up the bal symbol */
  3176.       S_SET_STORAGE_CLASS (balP, C_LABEL);
  3177. #endif /* OBJ_COFF */
  3178.     }                /* only on calls */
  3179. }
  3180.  
  3181. void
  3182. i960_handle_align (fragp)
  3183.      fragS *fragp;
  3184. {
  3185.   if (!linkrelax)
  3186.     return;
  3187.  
  3188. #ifndef OBJ_BOUT
  3189.  
  3190.   as_bad ("option --link-relax is only supported in b.out format");
  3191.   linkrelax = 0;
  3192.   return;
  3193.  
  3194. #else
  3195.  
  3196.   /* The text section "ends" with another alignment reloc, to which we
  3197.      aren't adding padding.  */
  3198.   if (fragp->fr_next == text_last_frag
  3199.       || fragp->fr_next == data_last_frag)
  3200.     return;
  3201.  
  3202.   /* alignment directive */
  3203.   fix_new (fragp, fragp->fr_fix, fragp->fr_offset, 0, 0, 0,
  3204.        (int) fragp->fr_type);
  3205. #endif /* OBJ_BOUT */
  3206. }
  3207.  
  3208. int
  3209. i960_validate_fix (fixP, this_segment_type, add_symbolPP)
  3210.      fixS *fixP;
  3211.      segT this_segment_type;
  3212.      symbolS **add_symbolPP;
  3213. {
  3214. #define add_symbolP (*add_symbolPP)
  3215.   if (fixP->fx_tcbit && TC_S_IS_CALLNAME (add_symbolP))
  3216.     {
  3217.       /* Relocation should be done via the associated 'bal'
  3218.          entry point symbol. */
  3219.  
  3220.       if (!TC_S_IS_BALNAME (tc_get_bal_of_call (add_symbolP)))
  3221.     {
  3222.       as_bad ("No 'bal' entry point for leafproc %s",
  3223.           S_GET_NAME (add_symbolP));
  3224.       return 1;
  3225.     }
  3226.       fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP);
  3227.     }
  3228. #if 0
  3229.   /* Still have to work out other conditions for these tests.  */
  3230.   {
  3231.     if (fixP->fx_tcbit)
  3232.       {
  3233.     as_bad ("callj to difference of two symbols");
  3234.     return 1;
  3235.       }
  3236.     reloc_callj (fixP);
  3237.     if ((int) fixP->fx_bit_fixP == 13)
  3238.       {
  3239.     /* This is a COBR instruction.  They have only a 13-bit
  3240.        displacement and are only to be used for local branches:
  3241.        flag as error, don't generate relocation.  */
  3242.     as_bad ("can't use COBR format with external label");
  3243.     fixP->fx_addsy = NULL;    /* No relocations please. */
  3244.     return 1;
  3245.       }
  3246.   }
  3247. #endif
  3248. #undef add_symbolP
  3249.   return 0;
  3250. }
  3251.  
  3252. /* end of tc-i960.c */
  3253.